Skip to content

Commit

Permalink
Merge pull request #194 from innoflash/fix/controller-gen
Browse files Browse the repository at this point in the history
feat(generator): allow passing custom Model name
  • Loading branch information
Mohammad-Alavi authored Dec 8, 2024
2 parents a9855f1 + a194c77 commit 41af64d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/Generator/Commands/ContainerApiGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ public function getUserInputs(): array|null
'--section' => $sectionName,
'--container' => $containerName,
'--file' => $route['controller'],
'--model' => $model,
'--ui' => $ui,
'--stub' => $route['stub'],
]);
Expand All @@ -360,6 +361,7 @@ public function getUserInputs(): array|null
$this->call('apiato:generate:controller', [
'--section' => $sectionName,
'--container' => $containerName,
'--model' => $model,
'--file' => 'Controller',
'--ui' => $ui,
'--stub' => 'crud',
Expand Down
2 changes: 2 additions & 0 deletions src/Generator/Commands/ContainerWebGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ public function getUserInputs(): array|null
'--section' => $sectionName,
'--container' => $containerName,
'--file' => $route['controller'],
'--model' => $model,
'--ui' => $ui,
'--stub' => $route['stub'],
]);
Expand All @@ -276,6 +277,7 @@ public function getUserInputs(): array|null
'--section' => $sectionName,
'--container' => $containerName,
'--file' => 'Controller',
'--model' => $model,
'--ui' => $ui,
'--stub' => 'crud',
]);
Expand Down
8 changes: 4 additions & 4 deletions src/Generator/Commands/ControllerGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -50,6 +51,9 @@ class ControllerGenerator extends GeneratorCommand implements ComponentsGenerato

public function getUserInputs(): array|null
{
$model = $this->checkParameterOrAsk('model', 'Enter the name of the Model that this controller uses', $this->containerName);
$models = Pluralizer::plural($model);

$ui = Str::lower($this->checkParameterOrChoice('ui', 'Select the UI for the controller', ['API', 'WEB'], 0));

$stub = Str::lower(
Expand All @@ -66,10 +70,6 @@ public function getUserInputs(): array|null

$basecontroller = Str::ucfirst($ui) . 'Controller';

// Name of the model (singular and plural)
$model = $this->containerName;
$models = Pluralizer::plural($model);

$entity = Str::camel($model);
$entities = Str::of($entity)->pluralStudly()->camel()->toString();

Expand Down

0 comments on commit 41af64d

Please sign in to comment.