FEATURE: add language table

This commit is contained in:
Michal Kváček
2016-07-21 23:11:05 +02:00
parent 949b1f7c61
commit db912c4c91
4 changed files with 108 additions and 0 deletions
+55
View File
@@ -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
View File
@@ -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
];
/**
+18
View File
@@ -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 = [];
}
@@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class MakeLangEnumerations extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('languages', function (Blueprint $table) {
$table->string('code', 8)
->primary();
$table->string('name')
->comment('Translated name for given language');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('languages');
}
}