#Issue on Select Field with a second level relation.

15 messages · Page 1 of 1 (latest)

stuck hedge
#

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(),
keen kilnBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

stuck hedge
#

many to many, sorry

trail vigil
stuck hedge
#

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 😁

loud wave
#

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.

stuck hedge
#
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?

loud wave
#

Looks like it should work if you have a media_id in the form

stuck hedge
#

Nope, the text input media_id is filled

loud wave
#
->pivotData(fn($get) => ['media_id' => $get('media_id') ])
stuck hedge
#

it works

#

THANKSSSSSSS