Skip to content

Commit a415b39

Browse files
committed
#750: Only use property fallback if use fallback is enabled./
1 parent acbcf55 commit a415b39

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/Models/Behaviors/HasTranslation.php

+8-9
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace A17\Twill\Models\Behaviors;
44

5+
use A17\Twill\Commands\Build;
56
use A17\Twill\Facades\TwillCapsules;
67
use Astrotomic\Translatable\Translatable;
8+
use Illuminate\Database\Eloquent\Builder;
79
use Illuminate\Database\Query\JoinClause;
810
use Illuminate\Support\Collection;
911

@@ -27,21 +29,16 @@ public function getTranslationModelNameDefault()
2729
return TwillCapsules::getCapsuleForModel(class_basename($this))->getTranslationModel();
2830
}
2931

30-
/**
31-
* @param \Illuminate\Database\Eloquent\Builder $query
32-
* @param string|null $locale
33-
* @return \Illuminate\Database\Eloquent\Builder|null
34-
*/
35-
public function scopeWithActiveTranslations($query, $locale = null)
32+
public function scopeWithActiveTranslations(Builder $query, ?string $locale = null): Builder
3633
{
3734
if (method_exists($query->getModel(), 'translations')) {
38-
$locale = $locale == null ? app()->getLocale() : $locale;
35+
$locale = $locale ?? app()->getLocale();
3936

4037
$query->whereHas('translations', function ($query) use ($locale) {
4138
$query->whereActive(true);
4239
$query->whereLocale($locale);
4340

44-
if (config('translatable.use_property_fallback', false)) {
41+
if (config('translatable.use_fallback') && config('translatable.use_property_fallback', false)) {
4542
$query->orWhere('locale', config('translatable.fallback_locale'));
4643
}
4744
});
@@ -50,11 +47,13 @@ public function scopeWithActiveTranslations($query, $locale = null)
5047
$query->whereActive(true);
5148
$query->whereLocale($locale);
5249

53-
if (config('translatable.use_property_fallback', false)) {
50+
if (config('translatable.use_fallback') && config('translatable.use_property_fallback', false)) {
5451
$query->orWhere('locale', config('translatable.fallback_locale'));
5552
}
5653
}]);
5754
}
55+
56+
return $query;
5857
}
5958

6059
/**

0 commit comments

Comments
 (0)