Skip to content

Commit

Permalink
Merge pull request #29 from Laravel-Lang/1.x
Browse files Browse the repository at this point in the history
Added check for existence of translation repository
  • Loading branch information
andrey-helldar authored Jun 23, 2024
2 parents 9812ac4 + a890a7f commit 1d68acb
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Console/ModelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace LaravelLang\Models\Console;

use Illuminate\Console\Command;
use LaravelLang\Config\Facades\Config;
use LaravelLang\Models\Generators\MigrationGenerator;
use LaravelLang\Models\Generators\ModelGenerator;
use LaravelLang\Models\Services\ClassMap;
Expand All @@ -17,6 +18,7 @@
use function Laravel\Prompts\error;
use function Laravel\Prompts\select;
use function Laravel\Prompts\text;
use function Laravel\Prompts\warning;

#[AsCommand(name: 'make:model-translation')]
class ModelMakeCommand extends Command
Expand All @@ -37,6 +39,12 @@ public function handle(): void
return;
}

if ($this->hasTranslation($model)) {
warning('The specified model already has a translation repository.');

return;
}

$columns = $this->columns();

$this->generateModel($model, $columns);
Expand Down Expand Up @@ -76,6 +84,11 @@ protected function validatedModel(string $model): ?string
return class_exists($model) ? $model : null;
}

protected function hasTranslation(string $model): bool
{
return class_exists($model . Config::shared()->models->suffix);
}

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

0 comments on commit 1d68acb

Please sign in to comment.