Skip to content

Commit 30551de

Browse files
author
Tihomir Banov
committed
Fix empty locale ckeck
1 parent 1fba782 commit 30551de

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/Despark/LaravelDbLocalization/i18nModelTrait.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,15 @@ public function getI18nId($locale = null)
6767
$locale = \App::getLocale();
6868
}
6969
$localeModel = Config::get('laravel-db-localization::locale_class');
70-
$i18n = $localeModel::select('id')->where('locale', $locale)->firstOrFail();
70+
$i18n = $localeModel::select('id')->where('locale', $locale)->first();
7171

72-
$this->i18nId = $i18n->id;
72+
$i18nId = null;
7373

74-
return $this->i18nId;
74+
if (isset($i18n->id)) {
75+
$i18nId = $i18n->id;
76+
}
77+
78+
return $i18nId;
7579
}
7680

7781
/**
@@ -86,10 +90,9 @@ public function translate($locale = false)
8690
if (!is_int($locale)) {
8791
$locale = $this->getI18nId($locale);
8892
}
89-
9093
$translation = null;
9194

92-
if (isset($this->id) && !$locale) {
95+
if (isset($this->id) && $locale) {
9396
$translation = $translationModel::where($this->translatorField, $this->id)
9497
->where($this->localeField, $locale)->first();
9598
}

0 commit comments

Comments
 (0)