From da5a25536dcd5e7172d40e3ae52493fb9eda0e21 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Thu, 19 Oct 2017 12:10:06 +0800 Subject: [PATCH] Add migration generator class --- src/CrudMake.php | 32 ++------------------------------ src/Generators/MigrationGenerator.php | 34 ++++++++++++++++++++++++++++++++++ src/Generators/ModelGenerator.php | 2 +- 3 files changed, 37 insertions(+), 31 deletions(-) create mode 100644 src/Generators/MigrationGenerator.php diff --git a/src/CrudMake.php b/src/CrudMake.php index cb6b24d..2f8f00c 100644 --- a/src/CrudMake.php +++ b/src/CrudMake.php @@ -5,6 +5,7 @@ namespace Luthfi\CrudGenerator; use Illuminate\Console\Command; use Illuminate\Filesystem\Filesystem; use Luthfi\CrudGenerator\Generators\ControllerGenerator; +use Luthfi\CrudGenerator\Generators\MigrationGenerator; use Luthfi\CrudGenerator\Generators\ModelGenerator; class CrudMake extends Command @@ -79,7 +80,7 @@ class CrudMake extends Command $this->generateResourceRoute(); app(ModelGenerator::class, ['command' => $this])->generate(); - $this->generateMigration(); + app(MigrationGenerator::class, ['command' => $this])->generate(); app(ControllerGenerator::class, ['command' => $this])->generate(); $this->generateViews(); $this->generateLangFile(); @@ -143,24 +144,6 @@ class CrudMake extends Command } /** - * Generate migration file for the model - * - * @return void - */ - public function generateMigration() - { - $prefix = date('Y_m_d_His'); - $tableName = $this->modelNames['table_name']; - - $migrationPath = $this->makeDirectory(database_path('migrations')); - - $migrationFilePath = $migrationPath.'/'.$prefix."_create_{$tableName}_table.php"; - $this->generateFile($migrationFilePath, $this->getMigrationContent()); - - $this->info($this->modelNames['model_name'].' table migration generated.'); - } - - /** * Generate the index view and forms view files * * @return void @@ -281,17 +264,6 @@ class CrudMake extends Command } /** - * Get migration file content from migration stub - * - * @return string Replaced proper model names in migration file content - */ - private function getMigrationContent() - { - $stub = $this->files->get(__DIR__.'/stubs/migration-create.stub'); - return $this->replaceStubString($stub); - } - - /** * Get index view file content from index view stub * * @return string Replaced proper model names in view file content diff --git a/src/Generators/MigrationGenerator.php b/src/Generators/MigrationGenerator.php new file mode 100644 index 0000000..8644841 --- /dev/null +++ b/src/Generators/MigrationGenerator.php @@ -0,0 +1,34 @@ +modelNames['table_name']; + + $migrationPath = $this->makeDirectory(database_path('migrations')); + + $migrationFilePath = $migrationPath.'/'.$prefix."_create_{$tableName}_table.php"; + $this->generateFile($migrationFilePath, $this->getContent()); + + $this->command->info($this->modelNames['model_name'].' table migration generated.'); + } + + /** + * {@inheritDoc} + */ + protected function getContent() + { + $stub = $this->files->get(__DIR__.'/../stubs/migration-create.stub'); + return $this->replaceStubString($stub); + } +} \ No newline at end of file diff --git a/src/Generators/ModelGenerator.php b/src/Generators/ModelGenerator.php index b5c1138..b18e611 100644 --- a/src/Generators/ModelGenerator.php +++ b/src/Generators/ModelGenerator.php @@ -3,7 +3,7 @@ namespace Luthfi\CrudGenerator\Generators; /** -* Controller Generator Class +* Model Generator Class */ class ModelGenerator extends BaseGenerator {