Skip to content

Commit

Permalink
Merge pull request #60 from cunio-martin/feature/configure_db_connection
Browse files Browse the repository at this point in the history
Feature: Ability to configure a DB connection for translations
  • Loading branch information
joedixon committed May 2, 2019
2 parents d8004f0 + bbc780a commit e2a7ee1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
3 changes: 3 additions & 0 deletions config/translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
|
*/
'database' => [

'connection' => '',

'languages_table' => 'languages',

'translations_table' => 'translations',
Expand Down
16 changes: 9 additions & 7 deletions database/migrations/2018_08_29_200844_create_languages_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ class CreateLanguagesTable extends Migration
*/
public function up()
{
Schema::create(config('translation.database.languages_table'), function (Blueprint $table) {
$table->increments('id');
$table->string('name')->nullable();
$table->string('language');
$table->timestamps();
});
Schema::connection(config('translation.database.connection'))
->create(config('translation.database.languages_table'), function (Blueprint $table) {
$table->increments('id');
$table->string('name')->nullable();
$table->string('language');
$table->timestamps();
});

Language::create([
'language' => config('app.locale'),
Expand All @@ -33,6 +34,7 @@ public function up()
*/
public function down()
{
Schema::dropIfExists(config('translation.database.languages_table'));
Schema::connection(config('translation.database.connection'))
->dropIfExists(config('translation.database.languages_table'));
}
}
23 changes: 13 additions & 10 deletions database/migrations/2018_08_29_205156_create_translations_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ class CreateTranslationsTable extends Migration
*/
public function up()
{
Schema::create(config('translation.database.translations_table'), function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('language_id');
$table->foreign('language_id')->references('id')->on(config('translation.database.languages_table'));
$table->string('group')->nullable();
$table->text('key');
$table->text('value')->nullable();
$table->timestamps();
});
Schema::connection(config('translation.database.connection'))
->create(config('translation.database.translations_table'), function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('language_id');
$table->foreign('language_id')->references('id')
->on(config('translation.database.languages_table'));
$table->string('group')->nullable();
$table->text('key');
$table->text('value')->nullable();
$table->timestamps();
});
}

/**
Expand All @@ -31,6 +33,7 @@ public function up()
*/
public function down()
{
Schema::dropIfExists(config('translation.database.translations_table'));
Schema::connection(config('translation.database.connection'))
->dropIfExists(config('translation.database.translations_table'));
}
}
1 change: 1 addition & 0 deletions src/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Language extends Model
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$this->connection = config('translation.database.connection');
$this->table = config('translation.database.languages_table');
}

Expand Down
1 change: 1 addition & 0 deletions src/Translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Translation extends Model
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$this->connection = config('translation.database.connection');
$this->table = config('translation.database.translations_table');
}

Expand Down

0 comments on commit e2a7ee1

Please sign in to comment.