This package improves support for sorting relations in Laravel Nova.
Install via composer
$ composer require lifeonscreen/nova-sort-relations
Include LifeOnScreen\SortRelations\SortRelations
trait to your class. Define base by overriding indexQuery
.
Define sortable columns in $sortRelations
array.
...
use LifeOnScreen\SortRelations\SortRelations;
...
class Product extends Resource
{
public static $sortRelations = [
// overriding id with product.id (this prevent ambiguous id, if you select multiple ids)
'id' => 'product.id',
// overriding user relation sorting
'user' => [
// sorting multiple columns
'users.name',
'users.surname',
],
// overriding company relation sorting
'company' => 'company.name',
];
public static function indexQuery(NovaRequest $request, $query)
{
// You can modify your base query here.
return $query;
}
}
If you discover any security-related issues, please email the author instead of using the issue tracker.
MIT license. Please see the license file for more information.