Skip to content

Commit

Permalink
Merge pull request #28 from Laravel-Lang/1.x
Browse files Browse the repository at this point in the history
Added check for model existence during generation
  • Loading branch information
andrey-helldar authored Jun 23, 2024
2 parents 308d71e + e5c2062 commit 9812ac4
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/Console/ModelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

use function array_filter;
use function array_merge;
use function class_exists;
use function compact;
use function Laravel\Prompts\error;
use function Laravel\Prompts\select;
use function Laravel\Prompts\text;

Expand All @@ -27,7 +29,14 @@ class ModelMakeCommand extends Command

public function handle(): void
{
$model = $this->model();
$model = $this->model();

if (! $this->validatedModel($model)) {
error("The model at `$model` namespace was not found.");

return;
}

$columns = $this->columns();

$this->generateModel($model, $columns);
Expand All @@ -50,18 +59,23 @@ protected function generateHelper(string $model): void
$this->call(ModelsHelperCommand::class, compact('model'));
}

protected function model(): string
protected function model(): ?string
{
if ($model = $this->argument('model')) {
return $model;
}

return select(
label : 'Select the model for which you want to create a translation repository:',
label : 'Select a model to create a translation repository:',
options: $this->models()
);
}

protected function validatedModel(string $model): ?string
{
return class_exists($model) ? $model : null;
}

protected function columns(): array
{
if ($columns = $this->option('columns')) {
Expand Down

0 comments on commit 9812ac4

Please sign in to comment.