Best method to order?

Hi all, I need to add a custom sort/order on my panel table. In short I need to order by more than just the one column. I wanted to check I am doing this the right way? or if there is a better method?
return $table
->modifyQueryUsing(fn (Builder $query) => $query->orderByRaw("date DESC, time DESC"))
return $table
->modifyQueryUsing(fn (Builder $query) => $query->orderByRaw("date DESC, time DESC"))
Solution:
I believe the better solution is to apply the sort options to the query passed to defaultSort :
Jump to solution
3 Replies
Solution
Tetracyclic
Tetracyclic6mo ago
I believe the better solution is to apply the sort options to the query passed to defaultSort :
Tetracyclic
Tetracyclic6mo ago
->defaultSort(function ($query, $direction) {
$query->orderBy(...);
})
->defaultSort(function ($query, $direction) {
$query->orderBy(...);
})
David | Fortune Validator
thank you, thats perfect, always learning. I tweaked it slight to this:
->defaultSort(fn ($query) => $query->orderBy('date','desc')->orderBy('time','desc'))
->defaultSort(fn ($query) => $query->orderBy('date','desc')->orderBy('time','desc'))
Want results from more Discord servers?
Add your server