© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
4 replies
morty

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
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(),
        ]),
])
->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()
->fillForm()
method but then the
->options()
->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
Select - Form Builder - Filament
Solution
->fillForm(fn (Model $record) => $record->collections->toArray())
->fillForm(fn (Model $record) => $record->collections->toArray())

?
options()
options()
isn't necessary I guess
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Dependant select in modal form
FilamentFFilament / ❓┊help
2y ago
How dynamically populate default form data when modal loads?
FilamentFFilament / ❓┊help
3y ago
TitleAttribute doesn't appear in Form Select
FilamentFFilament / ❓┊help
2y ago
Additional data in a Select component?
FilamentFFilament / ❓┊help
2y ago