F
Filament14mo ago
ericmp

Creating an order filter doesnt work as expected

in one of my tables i have this filter:
SelectFilter::make('order')
->default(0)
->options([
0 => __('Discovery'),
1 => __('Latest'),
2 => __('Random'),
])
->query(function (Builder $query, array $data): Builder {
return $query
->when($data['value'] == 0, function ($q) {
$q->orderBy('discovered_at', 'desc');
})
->when($data['value'] == 1, function ($q) {
$q->latest();
})
->when($data['value'] == 2, function ($q) {
$q->inRandomOrder();
})
;
})
,
SelectFilter::make('order')
->default(0)
->options([
0 => __('Discovery'),
1 => __('Latest'),
2 => __('Random'),
])
->query(function (Builder $query, array $data): Builder {
return $query
->when($data['value'] == 0, function ($q) {
$q->orderBy('discovered_at', 'desc');
})
->when($data['value'] == 1, function ($q) {
$q->latest();
})
->when($data['value'] == 2, function ($q) {
$q->inRandomOrder();
})
;
})
,
but it just doesnt work why?
1 Reply
ericmp
ericmpOP14mo ago
using debugbar, i see that despite of im changing the select's value in the frontend, the query is the same then to test it more deeply, i added:
$q->where('id', '>', 0); // just to test what would happen in debugbar
$q->where('id', '>', 0); // just to test what would happen in debugbar
and in debugbar yeah, i see the where so why is it not ordering!?
Want results from more Discord servers?
Add your server