filament
filament copied to clipboard
Allow orderby (and other mysql stuff) in filters
I might be completely incorrect, but I think this would allow users to use filters for ordering their tables. I do understand this might not be wanted so feel free to decline the PR if that's the case.
Especially nifty if you're using the Layout::AboveContent, which with a little bit of css might give a filter the look of being an order dropdown instead of a filter.
Currently doing:
Filter::make('Sorteervolgorde')
->form([
Select::make('Sorteervolgorde')
->disablePlaceholderSelection()
->options([
'newestFirst' => 'Nieuwste eerst',
'oldestFirst' => 'Oudste eerst',
]),
])
->query(function (Builder $query, array $data): Builder {
return $query
->when($data['Sorteervolgorde'] === 'newestFirst',
fn(Builder $query) => $query->orderBy('id', 'DESC'))
->when($data['Sorteervolgorde'] === 'oldestFirst',
fn(Builder $query) => $query->orderBy('id'));
}),
Is not possible as the current implementation only allows where queries. This change would allow this example to work.