© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•11mo ago•
4 replies
billyma121182

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'),
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
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
Select - Forms - Filament
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Adding a SelectFilter with relationship breaks table ordering
FilamentFFilament / ❓┊help
3y ago
Table SelectFilter
FilamentFFilament / ❓┊help
9mo ago
SelectFilter->getOptionLabelFromRecordUsing
FilamentFFilament / ❓┊help
13mo ago
SelectFIlter & AsEnumCollection
FilamentFFilament / ❓┊help
2y ago