FIX: do not use localization service provider in CLI

This commit is contained in:
Michal Kváček
2016-07-23 22:28:54 +02:00
parent 3733d24da8
commit 6b24c8a461
@@ -1,5 +1,7 @@
<?php namespace App\Providers;
use App\Models\Language;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\ServiceProvider;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
@@ -9,17 +11,27 @@ class LaravelLocalizationServiceProvider extends ServiceProvider
{
public function register()
{
// localization is not important in running in CLI
if (App::runningInConsole()) {
return;
}
$languages = DB::table('languages')
->get();
$supportedLocales = [
config('app.locale') => [
$supportedLocales = [];
if (empty($languages)) {
$supportedLocales[config('app.locale')] = (object)[
'native' => env('LOCALE_NATIVE_NAME'),
'script' => env('LOCALE_SCRIPT'),
'name' => env('LOCALE_TRANSLATED_NAME'),
]
];
'code' => config('app.locale'),
];
// create default language
Language::create((array)$supportedLocales[config('app.locale')]);
}
foreach ($languages as $language) {
$supportedLocales[$language->code] = [
'native' => $language->native,