From 6021f1ea9a695397ffd52f8632d9d8f3257b347a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Fri, 22 Jul 2016 00:43:29 +0200 Subject: [PATCH] FEATURE: add fields for languages --- app/Console/Commands/AddLanguage.php | 11 +++++- app/Models/Language.php | 6 +-- ...16_07_21_221547_AddFieldsIntoLanguages.php | 37 +++++++++++++++++++ 3 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 database/migrations/2016_07_21_221547_AddFieldsIntoLanguages.php diff --git a/app/Console/Commands/AddLanguage.php b/app/Console/Commands/AddLanguage.php index f4eb3308..b24ce5be 100644 --- a/app/Console/Commands/AddLanguage.php +++ b/app/Console/Commands/AddLanguage.php @@ -12,7 +12,7 @@ class AddLanguage extends Command * * @var string */ - protected $signature = 'language:add {code} {translation}'; + protected $signature = 'language:add {code} {translation} {native} {script?}'; /** * The console command description. * @@ -39,6 +39,8 @@ class AddLanguage extends Command { $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); @@ -48,7 +50,12 @@ class AddLanguage extends Command return; } - Language::create(['code' => $code, 'name' => $translation]); + Language::create([ + 'code' => $code, + 'name' => $translation, + 'native' => $native, + 'script' => $script ? $script : 'Latn' + ]); $this->line('Successfully installed.'); } diff --git a/app/Models/Language.php b/app/Models/Language.php index 3aca77ac..2cef168a 100644 --- a/app/Models/Language.php +++ b/app/Models/Language.php @@ -8,11 +8,11 @@ class Language extends Model { public $timestamps = false; public $primaryKey = 'code'; - protected $fillable = [ 'code', - 'name' + 'name', + 'script', + 'native' ]; - protected $guarded = []; } \ No newline at end of file diff --git a/database/migrations/2016_07_21_221547_AddFieldsIntoLanguages.php b/database/migrations/2016_07_21_221547_AddFieldsIntoLanguages.php new file mode 100644 index 00000000..434c5c45 --- /dev/null +++ b/database/migrations/2016_07_21_221547_AddFieldsIntoLanguages.php @@ -0,0 +1,37 @@ +string('script', 16) + ->default('Latn') + ->comment('ISO code for locale script (Latn, Arab, ...)'); + $table->string('native') + ->comment('Native name for language'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('languages', function (Blueprint $table) { + $table->dropColumn('script'); + $table->dropColumn('native'); + }); + } +}