F
Filament9mo ago
morty

Is there a way to group options on a select when using a relationship?

It appears that using both ->options() and ->relationship doesn't really play well together. I'm trying to create group options like seen here: https://filamentphp.com/docs/3.x/forms/fields/select#grouping-options When I do this and try to select an option, I get the following error:
SQLSTATE[42S22]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Invalid column name 'collections'.
When I instead use the relationship method, then the options method doesn't seem to work. My code:
Tables\Filters\SelectFilter::make('collections')
->label('Collections')
->multiple()
->options([
'Private collections' => AccountCollection::ownedByCurrentUser()->private()->orderBy('name')->pluck('name', 'id')->all(),
'Public collections' => AccountCollection::public()->orderBy('name')->pluck('name', 'id')->all(),
]),
Tables\Filters\SelectFilter::make('collections')
->label('Collections')
->multiple()
->options([
'Private collections' => AccountCollection::ownedByCurrentUser()->private()->orderBy('name')->pluck('name', 'id')->all(),
'Public collections' => AccountCollection::public()->orderBy('name')->pluck('name', 'id')->all(),
]),
1 Reply
morty
mortyOP9mo ago
Adding ->relationship('collections', 'name')->preload() to the filter doesn't work. It wipes out the options and fills results from the relationship which is normally fine but I can't group options this way.
Want results from more Discord servers?
Add your server