Skip to content

Commit

Permalink
Fix locale null with Filament v3 (#32)
Browse files Browse the repository at this point in the history
Co-authored-by: nhat.ta <nhat.ta@skillspar.com>
  • Loading branch information
jackbaron and nhat.ta authored Apr 17, 2024
1 parent 0ce43fc commit a2daae9
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/UniqueTranslationValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Illuminate\Support\Arr;

class UniqueTranslationValidator
{
Expand All @@ -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)
);

Expand Down Expand Up @@ -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];
}

Expand Down

0 comments on commit a2daae9

Please sign in to comment.