field relationship sort order

If I have a Select with a relationship, is there an easy way to sort the relation options by a custom order (i.e. in this example, categories would have a sort attribute)? Want to avoid adding scope or constructor to the model if possible.
Forms\Components\Select::make('category_id')
->relationship('category', 'category')
->required(),
Forms\Components\Select::make('category_id')
->relationship('category', 'category')
->required(),
2 Replies
LeandroFerreira
->relationship('category', 'category', fn (Builder $query): Builder => $query->orderBy('custom_column', 'asc/desc'))
->relationship('category', 'category', fn (Builder $query): Builder => $query->orderBy('custom_column', 'asc/desc'))
https://filamentphp.com/docs/2.x/forms/fields#populating-automatically-from-a-relationship
Filament
Fields - Form Builder - Filament
The elegant TALL stack form builder for Laravel artisans.
FullyLoadedTech
FullyLoadedTechOP2y ago
Perfect thank you!
Want results from more Discord servers?
Add your server