Fill Not Working - MultiSelect - With Pivot Table Relationship

I'm trying to create an Action to select some Travelers to attach to an Trip.

I have a table called 'trip_travelers' that has 'trip_id' and 'traveler_id'.

Trip Model:
    public function travelers(): BelongsToMany
    {
        return $this->belongsToMany(Traveler::class, 'trip_travelers');
    }


The same with Travelers.

I made a relationManager with createAction as default and it works like a Charm, creating records and already attaching with Model. But I need to create an Action to Attach existing Travelers so I decided to use a MultiSelect with custom Action to open a modal and select the Travelers. The problem is that fillForm is not filling my form with selected options.

My Action:

                Action::make('Manage Traveler')
                    ->record($this->ownerRecord)
                    ->model(Traveler::class)
                    ->fillForm(function ($record) {
                        return $this->ownerRecord->travelers()->get()->toArray();
                    })
                    ->form(function () {
                        return [
                            MultiSelect::make('travelers')
                                ->model(Trip::class)
                                ->relationship('travelers', 'first_name')
                                ->preload()
                                ->options(
                                    function () {
                                        return Traveler::query()->where('client_id', $this->ownerRecord->client_id)->pluck('first_name', 'id');
                                    }
                                )
                                ->createOptionForm(function () {
                                    return Traveler::getForm();
                                })
                                ->required()
                        ];
                    })


My relationManager is attached to TripResource.
Was this page helpful?