Select->relationship order

I've just found Filament and am loving it! Is it possible to specify a sort order when displaying a select with a relationship? Rather than have the options in alpha order by name?
Select::make('category')
-> relationship('category','name')->orderby('category.id', 'DESC'),
Select::make('category')
-> relationship('category','name')->orderby('category.id', 'DESC'),
Thanks, c-monster
2 Replies
awcodes
awcodes11mo ago
There’s a third parameter for relationship() where you can override the query.
c-monster
c-monsterOP11mo ago
Thanks for the clue and pushing me to work it out.
Select::make('category')
->relationship(
name: 'category',
titleAttribute:'name', modifyQueryUsing:fn(Builder $query)=>$query->orderBy('id','asc')),
Select::make('category')
->relationship(
name: 'category',
titleAttribute:'name', modifyQueryUsing:fn(Builder $query)=>$query->orderBy('id','asc')),
Want results from more Discord servers?
Add your server