Skip to content
This repository was archived by the owner on Jan 27, 2020. It is now read-only.

Commit c975a70

Browse files
committed
update translatable_required validation rule
1 parent 60d6ef1 commit c975a70

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/MultilingualServiceProvider.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,28 @@ class MultilingualServiceProvider extends ServiceProvider
1414
*/
1515
public function boot()
1616
{
17+
$systemLocales = config('multilingual.locales');
18+
1719
$this->publishes([
1820
__DIR__ . '/config/multilingual.php' => config_path('multilingual.php'),
1921
]);
2022

21-
$this->app['validator']->extendImplicit('translatable_required', function ($attribute, $value, $parameters) {
23+
24+
$this->app['validator']->extendImplicit('translatable_required', function ($attribute, $value, $parameters) use ($systemLocales) {
2225
if ( ! is_array($value)) return false;
2326

2427
// Get only the locales that has a value and exists in
2528
// the system locales array
26-
$locales = array_filter(array_keys($value), function ($locale) use ($value) {
27-
return @$value[$locale] && in_array($locale, config('multilingual.locales'));
29+
$locales = array_filter(array_keys($value), function ($locale) use ($value, $systemLocales) {
30+
return @$value[$locale] && in_array($locale, $systemLocales);
2831
});
2932

30-
return $locales == config('multilingual.locales');
33+
foreach ($systemLocales as $systemLocale) {
34+
if ( ! in_array($systemLocale, $locales))
35+
return false;
36+
}
37+
38+
return true;
3139
});
3240
}
3341

0 commit comments

Comments
 (0)