Tricks

Allow multiple records in a Attach select

Sep 21, 2022
Dennis
Admin panel, Table builder

With the default Filament select, it is possible to have a single select (inside the modal) to attach relationships. Sadly, you can't attach multiple records with the default select.

Solving this is fairly easy, we'll take an AttachAction as example:

Tables\Actions\AttachAction::make()

Change this to:

Tables\Actions\AttachAction::make()
->recordSelect(function (Select $select) {
return $select->multiple();
}),

Now, the AttachAction select is a multi-select.

avatar

Note: You need to use Filament\Forms\Components\Select; for this.

Unfortunately this does not seem with more recent filament versions anymore. A MultiSelect is rendered but only one record can be selected at a time :(.

avatar

You are right. It does not work with the latest filament version.

avatar

Great feature, sad it's still not working on recent version. Is there a issue opened on Github already?

avatar

I can confirm this works for me on filamentphp v3 :-)

avatar

Works perfectly with version 3.0.94

Shorter version:

Tables\Actions\AttachAction::make()
->recordSelect(fn (Select $select) => $select->multiple())