diff --git a/config/translator.php b/config/translator.php index 0a66ce0..394da40 100644 --- a/config/translator.php +++ b/config/translator.php @@ -18,6 +18,16 @@ */ 'source' => env('TRANSLATION_SOURCE', 'files'), + /* + |-------------------------------------------------------------------------- + | Default Translation Connection + |-------------------------------------------------------------------------- + | + | This option controls the translation's connection. By default is use Laravel default connection. In most cases + | you don't need to change it. + */ + 'connection' => config('database.default', env('TRANSLATOR_CONNECTION', 'mysql')), + // In case the files source is selected, please enter here the supported locales for your app. // Ex: ['en', 'es', 'fr'] 'available_locales' => [], diff --git a/database/migrations/2013_07_25_145943_create_languages_table.php b/database/migrations/2013_07_25_145943_create_languages_table.php index 17796c2..db53c55 100644 --- a/database/migrations/2013_07_25_145943_create_languages_table.php +++ b/database/migrations/2013_07_25_145943_create_languages_table.php @@ -12,7 +12,7 @@ class CreateLanguagesTable extends Migration */ public function up() { - Schema::create('translator_languages', function ($table) { + Schema::connection(config('translator.connection'))->create('translator_languages', function ($table) { $table->increments('id'); $table->string('locale', 6)->unique(); $table->string('name', 60)->unique(); diff --git a/database/migrations/2013_07_25_145958_create_translations_table.php b/database/migrations/2013_07_25_145958_create_translations_table.php index 305c35b..447f3eb 100644 --- a/database/migrations/2013_07_25_145958_create_translations_table.php +++ b/database/migrations/2013_07_25_145958_create_translations_table.php @@ -12,7 +12,7 @@ class CreateTranslationsTable extends Migration */ public function up() { - Schema::create('translator_translations', function ($table) { + Schema::connection(config('translator.connection'))->create('translator_translations', function ($table) { $table->increments('id'); $table->string('locale', 6); $table->string('namespace')->default('*'); diff --git a/database/migrations/2016_06_02_124154_increase_locale_length.php b/database/migrations/2016_06_02_124154_increase_locale_length.php index 6863586..aeecc57 100644 --- a/database/migrations/2016_06_02_124154_increase_locale_length.php +++ b/database/migrations/2016_06_02_124154_increase_locale_length.php @@ -12,10 +12,10 @@ class IncreaseLocaleLength extends Migration */ public function up() { - Schema::table('translator_languages', function ($table) { + Schema::connection(config('translator.connection'))->table('translator_languages', function ($table) { $table->string('locale', 10)->change(); }); - Schema::table('translator_translations', function ($table) { + Schema::connection(config('translator.connection'))->table('translator_translations', function ($table) { $table->string('locale', 10)->change(); }); } diff --git a/src/Models/Language.php b/src/Models/Language.php index 0a09c17..bf5f928 100644 --- a/src/Models/Language.php +++ b/src/Models/Language.php @@ -18,6 +18,17 @@ class Language extends Model */ protected $fillable = ['locale', 'name']; + /** + * Language constructor. + * @param array $attributes + */ + public function __construct(array $attributes = []) + { + parent::__construct($attributes); + + $this->setConnection(config('translator.connection')); + } + /** * Each language may have several translations. */ diff --git a/src/Models/Translation.php b/src/Models/Translation.php index 94d2d63..63aa323 100644 --- a/src/Models/Translation.php +++ b/src/Models/Translation.php @@ -16,6 +16,13 @@ class Translation extends Model */ protected $fillable = ['locale', 'namespace', 'group', 'item', 'text', 'unstable']; + public function __construct(array $attributes = []) + { + parent::__construct($attributes); + + $this->setConnection(config('translator.connection')); + } + /** * Each translation belongs to a language. */