F
Filament17mo ago
Stevee

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
N1XN
N1XN17mo ago
I am also interested in this as I currently have to do this:
Select::make('unit_id')
->relationship('unit', 'name->de') // kinda sucks
->label('Einheit')
->reactive()
->required(),
Select::make('unit_id')
->relationship('unit', 'name->de') // kinda sucks
->label('Einheit')
->reactive()
->required(),
Mohamed Melouk
Mohamed Melouk16mo ago
same issue
pocket.racer
pocket.racer16mo ago
will be interested in the solution as well
MohamedSabil83
MohamedSabil8315mo ago
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
SLy
SLy15mo ago
@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(),
MohamedSabil83
MohamedSabil8315mo ago
Maybe it works for me because I add Translatable::fallback(fallbackAny: true); to my service provider
SLy
SLy15mo ago
Still no luck, thanks anyway.
Aidas
Aidas12mo ago
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.

Did you find this page helpful?