Mojopollo\Schema\MakeMigrationJson::setMigrationName PHP Method

setMigrationName() public method

Creates a migration name from a table name or keeps it intact if a migration name has already been set
public setMigrationName ( string $tableName ) : string
$tableName string The original table name (Example: users, cats, create_users_table)
return string The migration name
    public function setMigrationName($tableName)
    {
        // Check if "_table" is already supplied or if this is a "pivot" table
        if (strpos($tableName, '_table') !== false || substr($tableName, -6) === '_pivot') {
            // Since the migration name has already been set, return it intact
            return $tableName;
        }
        // Create migration name
        return "create_{$tableName}_table";
    }

Usage Example

 /**
  * Test setMigrationName()
  *
  * @return void
  */
 public function testSetMigrationName()
 {
     // Make sure table names are converted into their proper migration name
     $tableName = 'users';
     $this->assertEquals($this->makeMigrationJson->setMigrationName($tableName), "create_{$tableName}_table");
     // Make sure migration names are not converted
     $tableName = 'remove_city_from_users_table';
     $this->assertEquals($this->makeMigrationJson->setMigrationName($tableName), $tableName);
 }