From 8d56da25d99c48949fab87eebc3537a629aecb80 Mon Sep 17 00:00:00 2001 From: Gentrit Abazi Date: Tue, 6 Oct 2020 23:22:19 +0200 Subject: [PATCH 1/3] Removed unused variable. --- src/Console/Stubs/services/service.stub | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Console/Stubs/services/service.stub b/src/Console/Stubs/services/service.stub index e2569ce..34a1318 100644 --- a/src/Console/Stubs/services/service.stub +++ b/src/Console/Stubs/services/service.stub @@ -38,8 +38,6 @@ class DummyClass { $dummyVariable = $this->dummyVariableRepository->create($data); - $dummyVariable->save(); - $this->dispatcher->dispatch(new DummyVariableWasCreated($dummyVariable)); return $dummyVariable; From 81145c5ad2d7d5afb8964808df458890ae607854 Mon Sep 17 00:00:00 2001 From: Gentrit Abazi Date: Thu, 8 Oct 2020 22:05:18 +0200 Subject: [PATCH 2/3] Removed unused class. --- src/Console/Stubs/controllers/controller.stub | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Console/Stubs/controllers/controller.stub b/src/Console/Stubs/controllers/controller.stub index 755bd73..da7d6cd 100644 --- a/src/Console/Stubs/controllers/controller.stub +++ b/src/Console/Stubs/controllers/controller.stub @@ -2,7 +2,6 @@ namespace DummyNamespace; -use DummyPath\Models\DummyVariable; use DummyPath\Services\DummyVariableService; use Illuminate\Http\Request; use Infrastructure\Http\Controller; From 93bf4a63f070e489789d6e1ba89feed73561d56d Mon Sep 17 00:00:00 2001 From: Gentrit Abazi Date: Thu, 8 Oct 2020 22:26:17 +0200 Subject: [PATCH 3/3] Added support for Plural and Singular. --- src/Console/ComponentMakeCommand.php | 19 ++++++++++++++----- src/Console/Stubs/controllers/controller.stub | 4 ++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Console/ComponentMakeCommand.php b/src/Console/ComponentMakeCommand.php index cd5b989..37ede91 100644 --- a/src/Console/ComponentMakeCommand.php +++ b/src/Console/ComponentMakeCommand.php @@ -4,6 +4,7 @@ use Illuminate\Console\Command; use Illuminate\Filesystem\Filesystem; +use Illuminate\Support\Str; class ComponentMakeCommand extends Command { @@ -158,6 +159,8 @@ protected function replaceClass($stub, $name, $fileName, $shortFileName) $stub = str_replace('DummyVariable', $class, $stub); $stub = str_replace('dummyVariable', lcfirst($class), $stub); $stub = str_replace('dummyvariable', strtolower($class), $stub); + $stub = str_replace('Singular_Dummy_Variable', Str::singular(strtolower($class)), $stub); + $stub = str_replace('Plural_Dummy_Variable', Str::plural(strtolower($class)), $stub); $stub = str_replace('DummyName', ucfirst($name), $stub); return str_replace('DummyClass', $this->argument('name'). ucfirst($shortFileName), $stub); @@ -210,13 +213,19 @@ public function handle() { $this->fire(); + $routePath = $this->argument('name'); + $routePath = strtolower($routePath); + $routePath = Str::plural($routePath); + $controllerName = $this->argument('name'); + $controllerName = ucfirst($controllerName); + $this->info( "Routes: ". PHP_EOL. - "$". "router->get('/". strtolower($this->argument('name')). "', '". ucfirst($this->argument('name')). "Controller@getAll');". PHP_EOL. - "$". "router->get('/". strtolower($this->argument('name')). "/{id}', '". ucfirst($this->argument('name')). "Controller@getById');". PHP_EOL. - "$". "router->post('/". strtolower($this->argument('name')). "', '". ucfirst($this->argument('name')). "Controller@create');". PHP_EOL. - "$". "router->put('/". strtolower($this->argument('name')). "/{id}', '". ucfirst($this->argument('name')). "Controller@update');". PHP_EOL. - "$". "router->delete('/". strtolower($this->argument('name')). "/{id}', '". ucfirst($this->argument('name')). "Controller@delete');". PHP_EOL + "$". "router->get('/". $routePath. "', '". $controllerName. "Controller@getAll');". PHP_EOL. + "$". "router->get('/". $routePath. "/{id}', '". $controllerName. "Controller@getById');". PHP_EOL. + "$". "router->post('/". $routePath. "', '". $controllerName. "Controller@create');". PHP_EOL. + "$". "router->put('/". $routePath. "/{id}', '". $controllerName. "Controller@update');". PHP_EOL. + "$". "router->delete('/". $routePath. "/{id}', '". $controllerName. "Controller@delete');". PHP_EOL ); } } diff --git a/src/Console/Stubs/controllers/controller.stub b/src/Console/Stubs/controllers/controller.stub index da7d6cd..1459f07 100644 --- a/src/Console/Stubs/controllers/controller.stub +++ b/src/Console/Stubs/controllers/controller.stub @@ -21,7 +21,7 @@ class DummyClass extends Controller $resourceOptions = $this->parseResourceOptions(); $data = $this->dummyVariableService->getAll($resourceOptions, true); - $parsedData = $this->parseData($data['rows'], $resourceOptions, 'rows'); + $parsedData = $this->parseData($data['rows'], $resourceOptions, 'Plural_Dummy_Variable'); $parsedData['total_data'] = $data['total_data']; return $this->response($parsedData); @@ -32,7 +32,7 @@ class DummyClass extends Controller $resourceOptions = $this->parseResourceOptions(); $data = $this->dummyVariableService->getById($dummyVariableId, $resourceOptions); - $parsedData = $this->parseData($data, $resourceOptions, 'row'); + $parsedData = $this->parseData($data, $resourceOptions, 'Singular_Dummy_Variable'); return $this->response($parsedData); }