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 existence of translation repository #29

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
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
Loading