From a2daae936dbc3bf0658c8d13ec6a9f9ff20357b1 Mon Sep 17 00:00:00 2001 From: Hoang Nhat Date: Wed, 17 Apr 2024 15:28:56 +0700 Subject: [PATCH] Fix locale null with Filament v3 (#32) Co-authored-by: nhat.ta --- src/UniqueTranslationValidator.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/UniqueTranslationValidator.php b/src/UniqueTranslationValidator.php index 118ea6e..c50c81e 100644 --- a/src/UniqueTranslationValidator.php +++ b/src/UniqueTranslationValidator.php @@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; +use Illuminate\Support\Arr; class UniqueTranslationValidator { @@ -25,7 +26,7 @@ public function validate($attribute, $value, $parameters, $validator) ? $this->getNovaAttributeNameAndLocale($attribute) : ( $this->isFilamentTranslation($attribute) - ? $this->getFilamentAttributeNameAndLocale($attribute) + ? $this->getFilamentAttributeNameAndLocale($attribute, $validator) : $this->getArrayAttributeNameAndLocale($attribute) ); @@ -110,10 +111,18 @@ protected function isFilamentTranslation($attribute) * * @return array */ - protected function getFilamentAttributeNameAndLocale($attribute) + protected function getFilamentAttributeNameAndLocale($attribute, $validator) { $attribute = str_replace('data.', '', $attribute); + + $dataValidator = $validator->getData(); + @list($name, $locale) = @explode('.', $attribute); + + if ($locale === null && Arr::exists($dataValidator, 'activeLocale')) { + $locale = $dataValidator['activeLocale']; + } + return [$name, $locale]; }