SelectFilter ordering

I am trying to order a select field options from a table in decending ID but can't see any way to do that in the docs.
Existing code below.
Thanks in advance for any tips.

SelectFilter::make('ItemProjectID')
  ->relationship('project', 'ProjectName')
  ->getOptionLabelFromRecordUsing(fn($record) => $record->NameAndID)
  ->label('Project'),
Solution
Since you're using the relationship() method, you can order the results of the query with its modifyQueryUsing parameter:

use Illuminate\Database\Eloquent\Builder;

SelectFilter::make('ItemProjectID')
  ->relationship(
    name: 'project', 
    titleAttribute: 'ProjectName',
    modifyQueryUsing: fn(Builder $query): Builder => $query->orderBy('id', 'desc')
)
//omitted for brevity


https://filamentphp.com/docs/3.x/forms/fields/select#customizing-the-relationship-query
Was this page helpful?