Skip to content

Commit

Permalink
Do not hardcode table name as it can be changed in config (#142)
Browse files Browse the repository at this point in the history
* Do not hardcode table name as it can be changed in config

* Only if model is actually extending Eloquent

* We need to define existing and migrated table name

* Late coding means typos.

* Oh, we need PHP 7 support then.
  • Loading branch information
AlexisSerneels authored Feb 18, 2022
1 parent a1b82cc commit 4a0e1d8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/TranslationLoaderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ class TranslationLoaderManager extends FileLoader
*/
public function load($locale, $group, $namespace = null): array
{
if (!Schema::hasTable('language_lines')) {
return parent::load($locale, $group, $namespace);
$modelClass = config('translation-loader.model');
$model = new $modelClass;
if (is_a($model, LanguageLine::class)) {
if (! Schema::hasTable($model->getTable())) {
return parent::load($locale, $group, $namespace);
}
}

$fileTranslations = parent::load($locale, $group, $namespace);
Expand Down
1 change: 1 addition & 0 deletions tests/TranslationLoaders/DbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public function it_flushes_the_cache_when_a_translation_has_been_deleted()
public function it_can_work_with_a_custom_model()
{
$alternativeModel = new class extends LanguageLine {
protected $table = 'language_lines';
public static function getTranslationsForGroup(string $locale, string $group): array
{
return ['key' => 'alternative class'];
Expand Down

0 comments on commit 4a0e1d8

Please sign in to comment.