From bb220f51535dc59522a05dc3f1fc21829052be47 Mon Sep 17 00:00:00 2001 From: Innocent Mazando Date: Fri, 19 Jan 2024 20:00:24 +0200 Subject: [PATCH 1/3] Fixed stub path in generator --- src/Generator/GeneratorCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Generator/GeneratorCommand.php b/src/Generator/GeneratorCommand.php index b94fb099..511490b5 100644 --- a/src/Generator/GeneratorCommand.php +++ b/src/Generator/GeneratorCommand.php @@ -233,7 +233,7 @@ protected function getStubContent(): string // Check if the custom file exists if (!$this->fileSystem->exists($file)) { // It does not exist - so take the default file! - $path = __DIR__ . 'GeneratorCommand.php/' . self::STUB_PATH; + $path = __DIR__ . '/' . self::STUB_PATH; $file = str_replace('*', $this->stubName, $path); } From 784872cf02d08a55f285dd16fdc7abaec1d82863 Mon Sep 17 00:00:00 2001 From: Innocent Mazando Date: Fri, 19 Jan 2024 20:01:13 +0200 Subject: [PATCH 2/3] Added expecting model --- src/Generator/Commands/ControllerGenerator.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Generator/Commands/ControllerGenerator.php b/src/Generator/Commands/ControllerGenerator.php index a96d1523..d4759e97 100644 --- a/src/Generator/Commands/ControllerGenerator.php +++ b/src/Generator/Commands/ControllerGenerator.php @@ -18,6 +18,7 @@ class ControllerGenerator extends GeneratorCommand implements ComponentsGenerato public array $inputs = [ ['ui', null, InputOption::VALUE_OPTIONAL, 'The user-interface to generate the Controller for.'], ['stub', null, InputOption::VALUE_OPTIONAL, 'The stub file to load for this generator.'], + ['model', null, InputOption::VALUE_OPTIONAL, 'The model you want to use for this controller.'], ]; /** * The console command name. @@ -73,6 +74,15 @@ public function getUserInputs(): null|array $entity = Str::lower($model); $entities = Pluralizer::plural($entity); + info('Controller info', [ + $this->stubName, + $basecontroller, + $model, + $models, + $entity, + $entities + ]); + return [ 'path-parameters' => [ 'section-name' => $this->sectionName, From 504275de13794ddaeb22e2a5490ad338e078e394 Mon Sep 17 00:00:00 2001 From: Innocent Mazando Date: Fri, 19 Jan 2024 20:09:44 +0200 Subject: [PATCH 3/3] Collecting model for controller --- src/Generator/Commands/ControllerGenerator.php | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/Generator/Commands/ControllerGenerator.php b/src/Generator/Commands/ControllerGenerator.php index d4759e97..827bfad1 100644 --- a/src/Generator/Commands/ControllerGenerator.php +++ b/src/Generator/Commands/ControllerGenerator.php @@ -51,6 +51,10 @@ class ControllerGenerator extends GeneratorCommand implements ComponentsGenerato public function getUserInputs(): null|array { + // Name of the model (singular and plural) + $model = $this->checkParameterOrAsk('model', 'Model for the controller.', $this->containerName); + $models = Pluralizer::plural($model); + $ui = Str::lower($this->checkParameterOrChoice('ui', 'Select the UI for the controller', ['API', 'WEB'], 0)); $stub = Str::lower( @@ -67,22 +71,9 @@ public function getUserInputs(): null|array $basecontroller = Str::ucfirst($ui) . 'Controller'; - // Name of the model (singular and plural) - $model = $this->containerName; - $models = Pluralizer::plural($model); - $entity = Str::lower($model); $entities = Pluralizer::plural($entity); - info('Controller info', [ - $this->stubName, - $basecontroller, - $model, - $models, - $entity, - $entities - ]); - return [ 'path-parameters' => [ 'section-name' => $this->sectionName,