Proposal for nullalbe translatable field

This commit is contained in:
Jérémy Munsch 2023-05-31 16:41:45 +02:00
parent b43f656f06
commit 4ec00f8835
No known key found for this signature in database
GPG key ID: 18361AF3BFEC0FEC

View file

@ -67,6 +67,42 @@ trait HasTranslations
return parent::mutateAttributeForArray($key, $value);
}
/**
* Filter transalations to fetch
*
* ! Fix of spatie translatable.
*
* @param mixed $value
* @param string|null $locale
* @param array|null $allowedLocales
* @return boolean
*/
protected function filterTranslations(
mixed $value = null,
string $locale = null,
array $allowedLocales = null
): bool {
if ($value === null) {
// ! Overload this to allow nullable.
return true;
}
if ($value === '') {
return false;
}
if ($allowedLocales === null) {
return true;
}
if (!in_array($locale, $allowedLocales)) {
return false;
}
return true;
}
/**
* Retrieve the model for a bound value.
*