LaravelPackages.net
Acme Inc.
Toggle sidebar
lifeonscreen/nova-sort-relations

This package improves support for sorting relations in Laravel Nova.

83.764
20
v0.0.2
About lifeonscreen/nova-sort-relations

lifeonscreen/nova-sort-relations is a Laravel package for this package improves support for sorting relations in laravel nova.. It currently has 20 GitHub stars and 83.764 downloads on Packagist (latest version v0.0.2). Install it with composer require lifeonscreen/nova-sort-relations. Discover more Laravel packages by lifeonscreen or browse all Laravel packages to compare alternatives.

Last updated

LifeOnScreen/nova-sort-relations

This package improves support for sorting relations in Laravel Nova.

Installation

Install via composer

$ composer require lifeonscreen/nova-sort-relations

Usage

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;
    }
}

Security

If you discover any security-related issues, please email the author instead of using the issue tracker.

Credits

License

MIT license. Please see the license file for more information.

Comments