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
awcodes5mo ago
There’s a third parameter for relationship() where you can override the query.
c-monster
c-monster5mo 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')),