Filament Spatie Translatable Plugin for relation model
how to do for the relation model at v3 ? it was fine at v2, did read the docs at https://github.com/filamentphp/spatie-laravel-translatable-plugin about the update but I think it only valid for translate the model itself
GitHub
GitHub - filamentphp/spatie-laravel-translatable-plugin: [READ ONLY...
[READ ONLY] Subtree split of the Filament spatie/laravel-translatable Plugin (see filamentphp/filament) - GitHub - filamentphp/spatie-laravel-translatable-plugin: [READ ONLY] Subtree split of the F...
8 Replies
I am also interested in this as I currently have to do this:
same issue
will be interested in the solution as well
In v3, you have to add
->getOptionLabelFromRecordUsing(fn ($record) => $record->name)
and keep relation as usual ->relationship('unit', 'name')
cc: @Stevee, @N1XN, and @pocket.racer@MohamedSabil83 For me this still does not work, I had to use the $livewire component to get activeLocale:
Forms\Components\Select::make('service_id')
->label('Service type')
->translateLabel()
->relationship( 'service', 'name',
)
//->getOptionLabelFromRecordUsing(fn (Service $service) => $service->name) //This does not work
->getOptionLabelFromRecordUsing(fn (Service $service, Livewire $livewire) => $service->getTranslation('name', $livewire->activeLocale)) // This works
->columnSpan(2)
->live()
->preload()
->required(),
Maybe it works for me because I add
Translatable::fallback(fallbackAny: true);
to my service providerStill no luck, thanks anyway.
Still no solution? I am stuck here as well, but also discoverd even more bugs with translatable. For example if your model does not use a translatable trait, but it has a translatable relation, entire edit form crashes as it forces your main model and resource to inject a translatable trait. And trait crashes as model does not have any translatable attributes. Yikes.