-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added filtering when using eager loading
- Loading branch information
1 parent
8ea3f60
commit e76a087
Showing
5 changed files
with
104 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaravelLang\Models\Eloquent\Scopes; | ||
|
||
use Illuminate\Database\Eloquent\Builder; | ||
use LaravelLang\Config\Facades\Config; | ||
use LaravelLang\Locales\Facades\Locales; | ||
|
||
use function array_unique; | ||
|
||
class FilterTranslationsScope | ||
{ | ||
public function __invoke(Builder $builder): void | ||
{ | ||
if ($this->enabled()) { | ||
$builder->whereIn('locale', $this->locales()); | ||
} | ||
} | ||
|
||
protected function enabled(): bool | ||
{ | ||
return Config::shared()->models->filter->enabled; | ||
} | ||
|
||
protected function locales(): array | ||
{ | ||
return array_unique([ | ||
Locales::getCurrent()->code, | ||
Locales::getFallback()->code, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Tests\Constants\FakeValue; | ||
|
||
dataset('locales-filter', [ | ||
'enabled' => [ | ||
'enabled' => true, | ||
'count' => 2, | ||
|
||
'locales' => [ | ||
FakeValue::LocaleFallback, | ||
FakeValue::LocaleMain, | ||
], | ||
], | ||
|
||
'disabled' => [ | ||
'enabled' => false, | ||
'count' => 3, | ||
|
||
'locales' => [ | ||
FakeValue::LocaleCustom, | ||
FakeValue::LocaleFallback, | ||
FakeValue::LocaleMain, | ||
], | ||
], | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters