FilamentF
Filament2y ago
Sydd

global search sort results

Please, i looking for solution sort global search results by column date_at descending, try this, but dont work:
public static function getGlobalSearchResults(string $search): Collection
    {
        return parent::getGlobalSearchResults($search)->sortByDesc('date_at');
    }
Solution
You probably need to order the query as opposed to the collection? 🤔

public static function getGlobalSearchEloquentQuery(): Builder
{
    return parent::getGlobalSearchEloquentQuery()->orderBy('date_at', 'desc');
}


See: https://filamentphp.com/docs/3.x/panels/resources/global-search#adding-extra-details-to-global-search-results
Was this page helpful?