From b762c98e4b360e8cf3d5ee6b86ab1b64d567e6de Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sun, 20 Aug 2017 22:14:29 +0800 Subject: [PATCH] Fixed controller creator to use controller.model.stub --- readme.md | 2 +- src/CrudMake.php | 8 +++- src/stubs/controller.model.stub | 65 +++++++++++++++++++++++++++++++++ tests/CrudMakeCommandTest.php | 81 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 src/stubs/controller.model.stub diff --git a/readme.md b/readme.md index a31b260..3e51e9f 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # Laravel Simple CRUD Generator -This is a package to create simple CRUD on your Laravel 5.4 application. +An artisan `make:crud` command to create a simple CRUD feature on your Laravel 5.4 application. > **Development in progress** diff --git a/src/CrudMake.php b/src/CrudMake.php index 1ae8259..590e6e0 100644 --- a/src/CrudMake.php +++ b/src/CrudMake.php @@ -44,7 +44,13 @@ class CrudMake extends Command $this->callSilent('make:model', ['name' => $model]); $this->info($model.' model generated.'); - $this->callSilent('make:controller', ['name' => $pluralModel.'Controller']); + + if (! $this->files->isDirectory(app_path('Http/Controllers'))) { + $this->files->makeDirectory(app_path('Http/Controllers'), 0777, true, true); + } + + $controllerPath = app_path('Http/Controllers/'.$pluralModel.'Controller.php'); + $this->files->put($controllerPath, $this->files->get(__DIR__.'/stubs/controller.model.stub')); $this->info($pluralModel.'Controller generated.'); $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$lowerCasePluralModel.'_table.php'); diff --git a/src/stubs/controller.model.stub b/src/stubs/controller.model.stub new file mode 100644 index 0000000..c5f3a9f --- /dev/null +++ b/src/stubs/controller.model.stub @@ -0,0 +1,65 @@ +artisan('make:crud', ['name' => 'Item', '--no-interaction' => true]); + + $this->assertFileExists(app_path('Item.php')); + $ctrlClassContent = "assertEquals($ctrlClassContent, file_get_contents(app_path('Http/Controllers/ItemsController.php'))); + exec('rm '.app_path('Item.php')); + exec('rm -r '.app_path('Http')); + exec('rm '.database_path('migrations/*')); + exec('rm -r '.resource_path('views/items')); + exec('rm -r '.base_path('tests/Feature')); + exec('rm -r '.base_path('tests/Unit')); + } }