© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•16mo ago•
14 replies
Eric

Sort table by random order

In my songs table, i want to add a filter to let the user choose to order the records randomly:

Tables\Filters\Filter::make('in_random_order')->query(fn (Builder $query): Builder => $query->inRandomOrder())
Tables\Filters\Filter::make('in_random_order')->query(fn (Builder $query): Builder => $query->inRandomOrder())


but if i check it or not, the results are the same. what could be happening? how can i make it to work?
Solution
Okay, I got curious so I added a 2000 song table to a fresh filament installation and did some experimenting. got it to work by using baseQuery instead of query (https://filamentphp.com/docs/3.x/tables/filters/getting-started#modifying-the-base-query) :
->filters([
  Filter::make('Shuffle')
    ->toggle() 
    ->baseQuery(fn (Builder $query) => $query->inRandomOrder())
    ->label('Shuffle Songs'),
])
->filters([
  Filter::make('Shuffle')
    ->toggle() 
    ->baseQuery(fn (Builder $query) => $query->inRandomOrder())
    ->label('Shuffle Songs'),
])
Getting started - Table Builder - 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

Order table by his relationship
FilamentFFilament / ❓┊help
3y ago
Persist sort order
FilamentFFilament / ❓┊help
2y ago
How to sort table by relationship?
FilamentFFilament / ❓┊help
15mo ago
field relationship sort order
FilamentFFilament / ❓┊help
3y ago