F
Filamentβ€’2mo ago
Peppe

Issue on Select Field with a second level relation.

Hi i write a simple Select with second level relation, and when i go to submit he give me this error
Forms\Components\Select::make('media.tags')
->label('Tag')
->placeholder('Seleziona')
->relationship('media.tags', 'label')
->required(),
Forms\Components\Select::make('media.tags')
->label('Tag')
->placeholder('Seleziona')
->relationship('media.tags', 'label')
->required(),
No description
Solution:
->pivotData(fn($get) => ['media_id' => $get('media_id') ])
->pivotData(fn($get) => ['media_id' => $get('media_id') ])
...
Jump to solution
10 Replies
LeandroFerreira
LeandroFerreiraβ€’2mo ago
what kind of relationship?
Peppe
PeppeOPβ€’2mo ago
many to many, sorry
LeandroFerreira
LeandroFerreiraβ€’2mo ago
https://filamentphp.com/docs/3.x/forms/fields/select#integrating-with-an-eloquent-relationship
Select::make('mediatags')
->relationship('yourrelationshipname', 'yourtitleattribute')
->multiple()
Select::make('mediatags')
->relationship('yourrelationshipname', 'yourtitleattribute')
->multiple()
Peppe
PeppeOPβ€’2mo ago
i tried right now, but still not working...
Forms\Components\Select::make('mediatags')
->label('Tag')
->multiple()
->preload()
->placeholder('Seleziona')
->relationship('media.tags', 'label')
->required(),
Forms\Components\Select::make('mediatags')
->label('Tag')
->multiple()
->preload()
->placeholder('Seleziona')
->relationship('media.tags', 'label')
->required(),
I've seen the docs before asking 😁
toeknee
toekneeβ€’2mo ago
media.tags is going through and the media isn't hasn't been set... you need to set the media_id
->pivotData([
'media_id' => @media_id here,
])
->pivotData([
'media_id' => @media_id here,
])
but I think what you really want is to select the media then have tags within the media it's self? which means you should use two relationships. Provide the full code ideally.
Peppe
PeppeOPβ€’2mo ago
Forms\Components\Select::make('mediatags')
->label('Tag')
->multiple()
->preload()
->placeholder('Seleziona')
->relationship('media.tags', 'label')
->pivotData(['media_id' => fn(Get $get) => $get('media_id') ])
->required(),

Forms\Components\TextInput::make('media_id'),
Forms\Components\Select::make('mediatags')
->label('Tag')
->multiple()
->preload()
->placeholder('Seleziona')
->relationship('media.tags', 'label')
->pivotData(['media_id' => fn(Get $get) => $get('media_id') ])
->required(),

Forms\Components\TextInput::make('media_id'),
i think i can't use like this?
toeknee
toekneeβ€’2mo ago
Looks like it should work if you have a media_id in the form
Peppe
PeppeOPβ€’2mo ago
Nope, the text input media_id is filled
No description
Solution
toeknee
toekneeβ€’2mo ago
->pivotData(fn($get) => ['media_id' => $get('media_id') ])
->pivotData(fn($get) => ['media_id' => $get('media_id') ])
Peppe
PeppeOPβ€’2mo ago
it works THANKSSSSSSS
Want results from more Discord servers?
Add your server