#Issue on Select Field with a second level relation.
15 messages · Page 1 of 1 (latest)
what kind of relationship?
many to many, sorry
https://filamentphp.com/docs/3.x/forms/fields/select#integrating-with-an-eloquent-relationship
Select::make('mediatags')
->relationship('yourrelationshipname', 'yourtitleattribute')
->multiple()
i tried right now, but still not working...
Forms\Components\Select::make('mediatags')
->label('Tag')
->multiple()
->preload()
->placeholder('Seleziona')
->relationship('media.tags', 'label')
->required(),
I've seen the docs before asking 😁
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,
])
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.
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?
Looks like it should work if you have a media_id in the form
Nope, the text input media_id is filled
->pivotData(fn($get) => ['media_id' => $get('media_id') ])