FEATURE: add language table
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?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}';
|
||||
/**
|
||||
* 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');
|
||||
|
||||
// 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]);
|
||||
|
||||
$this->line('Successfully installed.');
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use App\Console\Commands\AddLanguage;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
@@ -21,6 +22,7 @@ class Kernel extends ConsoleKernel
|
||||
Commands\TranslateAll::class,
|
||||
Commands\InitDatabaseSchema::class,
|
||||
Commands\SetTheme::class,
|
||||
AddLanguage::class
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Language extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
public $primaryKey = 'code';
|
||||
|
||||
protected $fillable = [
|
||||
'code',
|
||||
'name'
|
||||
];
|
||||
|
||||
protected $guarded = [];
|
||||
}
|
||||
Reference in New Issue
Block a user