From 0020a19a31080bcd78d417ab8d5b46536dd964b3 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sun, 20 Aug 2017 21:12:22 +0800 Subject: [PATCH] Added migration file generator --- src/CrudMake.php | 16 ++++++++++------ src/stubs/migration-create.stub | 33 +++++++++++++++++++++++++++++++++ tests/CrudMakeCommandTest.php | 5 +++++ 3 files changed, 48 insertions(+), 6 deletions(-) create mode 100755 src/stubs/migration-create.stub diff --git a/src/CrudMake.php b/src/CrudMake.php index d8da5d7..1ae8259 100644 --- a/src/CrudMake.php +++ b/src/CrudMake.php @@ -42,19 +42,23 @@ class CrudMake extends Command $pluralModel = str_plural($model); $lowerCasePluralModel = strtolower($pluralModel); - $this->callSilent('make:model', ['name' => $model]); $this->info($model.' model generated.'); $this->callSilent('make:controller', ['name' => $pluralModel.'Controller']); $this->info($pluralModel.'Controller generated.'); - $path = resource_path('views/'.$lowerCasePluralModel); - if (! $this->files->isDirectory($path)) { - $this->files->makeDirectory($path, 0777, true, true); + $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$lowerCasePluralModel.'_table.php'); + $this->files->put($migrationFilePath, $this->files->get(__DIR__.'/stubs/migration-create.stub')); + $this->info($model.' table migration generated.'); + + $viewPath = resource_path('views/'.$lowerCasePluralModel); + if (! $this->files->isDirectory($viewPath)) { + $this->files->makeDirectory($viewPath, 0777, true, true); } - $this->files->put($path.'/index.blade.php', $this->files->get(__DIR__.'/stubs/view-index.stub')); - $this->files->put($path.'/forms.blade.php', $this->files->get(__DIR__.'/stubs/view-forms.stub')); + $this->files->put($viewPath.'/index.blade.php', $this->files->get(__DIR__.'/stubs/view-index.stub')); + $this->files->put($viewPath.'/forms.blade.php', $this->files->get(__DIR__.'/stubs/view-forms.stub')); + $this->info($model.' view files generated.'); $this->callSilent('make:test', ['name' => 'Manage'.$pluralModel.'Test']); $this->info('Manage'.$pluralModel.'Test generated.'); diff --git a/src/stubs/migration-create.stub b/src/stubs/migration-create.stub new file mode 100755 index 0000000..526548f --- /dev/null +++ b/src/stubs/migration-create.stub @@ -0,0 +1,33 @@ +increments('id'); + $table->string('name', 60); + $table->string('description'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('DummyTable'); + } +} diff --git a/tests/CrudMakeCommandTest.php b/tests/CrudMakeCommandTest.php index ac355a8..d672f8e 100644 --- a/tests/CrudMakeCommandTest.php +++ b/tests/CrudMakeCommandTest.php @@ -16,6 +16,10 @@ class CrudMakeCommandTest extends TestCase $this->assertFileExists(app_path('Test.php')); $this->assertFileExists(app_path('Http/Controllers/TestsController.php')); + + $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_tests_table.php'); + $this->assertFileExists($migrationFilePath); + $this->assertFileExists(resource_path('views/tests/index.blade.php')); $this->assertFileExists(resource_path('views/tests/forms.blade.php')); $this->assertFileExists(base_path('tests/Feature/ManageTestsTest.php')); @@ -23,6 +27,7 @@ class CrudMakeCommandTest extends TestCase exec('rm '.app_path('Test.php')); exec('rm -r '.app_path('Http')); + exec('rm '.$migrationFilePath); exec('rm -r '.resource_path('views/tests')); exec('rm -r '.base_path('tests/Feature')); exec('rm -r '.base_path('tests/Unit'));