BelongsToMany Select component doesn't populate data in a modal form

I have an action on a table that opens a modal form to manage a BelongsToMany (many-to-many) relationship. This is my action code on my table:

->actions([
    Tables\Actions\Action::make('collections')
        ->label('Manage collections')
        ->icon('heroicon-o-rectangle-stack')
        ->slideOver()
        ->modalWidth(MaxWidth::Medium)
        ->modalIcon('heroicon-o-rectangle-stack')
        ->form([
            Forms\Components\Select::make('collections')
                ->label('Collections')
                ->multiple()
                ->relationship('collections', 'name')
                ->options(AccountCollection::mine()->pluck('name', 'id'))
                ->required(),
        ]),
])


According to the documentation: https://filamentphp.com/docs/3.x/forms/fields/select#integrating-with-an-eloquent-relationship

Filament will load the options from the relationship, and save them back to the relationship's pivot table when the form is submitted.

Filament is saving no problem, but it's not loading the values already associated with the model.

I tried using the ->fillForm() method but then the ->options() array is blank. I don't understand what I'm doing wrong here?

In the screenshot, some of these options are already associated with this account but the form doesn't indicate this.
CleanShot_2024-03-05_at_14.51.00.png
Solution
->fillForm(fn (Model $record) => $record->collections->toArray())

?
options() isn't necessary I guess
Was this page helpful?