Skip to main content
Resource Lists · Revision #1

How do I add a sort by to an existing resource list?

How do I add a sort by to an existing resource list?

You can use the addSortBy() method to add a filter to an existing resource list:

\Aero\Admin\ResourceLists\OrdersResourceList::extend(function (\Aero\Admin\ResourceLists\OrdersResourceList $list, \Closure $next) {
    $list->addSortBy(\Aero\Admin\ResourceLists\ResourceListSortBy::create([
        'latest' => 'Latest',
        'oldest' => 'Oldest',
    ], function ($sortBy, $query) {
        return $sortBy === 'oldest' ? $query->orderBy('created_at') : $query->orderByDesc('created_at');
    }));

    return $next($list);
});