63 lines
1.4 KiB
PHP
63 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\Language;
|
|
use Illuminate\Console\Command;
|
|
|
|
class AddLanguage extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'language:add {code} {translation} {native} {script?}';
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Insert new language into database';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
$code = $this->argument('code');
|
|
$translation = $this->argument('translation');
|
|
$native = $this->argument('native');
|
|
$script = $this->argument('script');
|
|
|
|
// check if language does not exist
|
|
$exist = Language::find($code);
|
|
|
|
if ($exist) {
|
|
$this->error('Language ' . $code . ' already exists!');
|
|
return;
|
|
}
|
|
|
|
Language::create([
|
|
'code' => $code,
|
|
'name' => $translation,
|
|
'native' => $native,
|
|
'script' => $script ? $script : 'Latn'
|
|
]);
|
|
|
|
$this->line('Successfully installed.');
|
|
}
|
|
}
|