Translatable plugin : make relationship field works
Hi ! I have a Mission model with a
institution() : BelongsTo
relationship. On my Mission edit page (resource), I want to show the institution.access_code
field but Filament doesn't translate it and try to display the entire object. How can I make it works (display the field in the current locale) ?
Solution:Jump to solution
->formatStateUsing(fn (string $state): string => $state['fr']['access_code'])
or
Forms\Components\TextInput::make('access_code.fr')...
9 Replies
add ->formatStateUsing(fn(state) => dd($state)
to the access_code field, what does it show?
So check your relatiomnship
The relationship is correct, the field was just empty. Now I have this :
It's object,object because it's received an obejct and not a string
so fr = a translation
access_code
is an access_code
Yep, I get it. It's automatic for resource fields but not for relationship fields.
I think I need something like that... I don't know.
Solution
->formatStateUsing(fn (string $state): string => $state['fr']['access_code'])
or
Forms\Components\TextInput::make('access_code.fr')
So weird, I was sure I tried
Forms\Components\TextInput::make('access_code.fr')
before, but it works now, thanks a lot @toeknee_iom !