Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added check for model existence during generation #28

Merged
merged 1 commit into from
Jun 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading