In laravel 10 / filamentphp 3 app with spatie/laravel-translatable 6.5.5 I have app/Models/Settings.php model with json field for translation labels.
In model I have :
namespace AppModels;
use IlluminateDatabaseEloquentModel;
use SpatieMediaLibraryHasMedia;
use SpatieMediaLibraryInteractsWithMedia;
use SpatieTranslatableHasTranslations;
class Settings extends Model implements HasMedia
{
use InteractsWithMedia;
use HasTranslations;
protected $table = 'settings';
protected $primaryKey = 'id';
public $timestamps = true;
protected $fillable = [
'name',
'value',
'updated_at',
];
public $translatable = ['value'];
public $cast = ['value'=>'json']; // Not shure if I really need this casting - commenting it I have the same result.
Problem is that when I try to get languale label I always get default english label, not in locale I request.
So with code :
$currentLocale = 'ua';
app()->setLocale($currentLocale);
echo '::app()->GetLocale::'.print_r(App::getLocale(),true);
$settings = Settings::getByName('site_name')->first();
echo '::RESULT::'.print_r($settings->getTranslation('value', $currentLocale),true); // // I got value "Quizzes"
var_dump($settings); // I see valid model with content in image below:
dd($dataArray->value); // I got value "Quizzes"
Output I have :
Database row :
What is wrong with my code ?