FEATURE #2520: add template for creating new table
This commit is contained in:
@@ -11,7 +11,7 @@ class CreateMigration extends Command
|
||||
* The name and signature of the console command.
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'module:make-migration {module?} {name?} {--t|table= : Table name}';
|
||||
protected $signature = 'module:make-migration {module?} {name?} {--t|table= : Table name} {--c|create : Use template for creating new table}';
|
||||
/**
|
||||
* The console command description.
|
||||
* @var string
|
||||
@@ -19,15 +19,16 @@ class CreateMigration extends Command
|
||||
protected $description = 'Make new migration for given module';
|
||||
protected $migrationName;
|
||||
protected $tableName;
|
||||
protected $moduleName;
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$module = $this->argument('module');
|
||||
$this->moduleName = $module = $this->argument('module');
|
||||
$this->migrationName = $name = $this->argument('name');
|
||||
$this->tableName = $this->option('table');
|
||||
$this->tableName = trim($this->option('table'), ' =');
|
||||
|
||||
$modules = Module::where('enabled', true)
|
||||
->get()
|
||||
@@ -51,7 +52,8 @@ class CreateMigration extends Command
|
||||
$name = $this->ask('Input migration name');
|
||||
}
|
||||
|
||||
$content = file_get_contents(config('modules.paths.stubs') . '/Migrations/new.stub');
|
||||
$stubName = $this->option('create') ? 'create' : 'new';
|
||||
$content = file_get_contents(config('modules.paths.stubs') . '/Migrations/'.$stubName.'.stub');
|
||||
$content = $this->replacePlaceholders($content);
|
||||
|
||||
$migrationName = $path . $this->getMigrationName($name);
|
||||
@@ -72,6 +74,7 @@ class CreateMigration extends Command
|
||||
{
|
||||
$replace = [
|
||||
'$MigrationName$' => studly_case($this->migrationName),
|
||||
'$ModuleName$' => $this->moduleName,
|
||||
'$TableName$' => $this->tableName
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user