Skip to content
This package improves support for sorting relations in Laravel Nova.
Branch: master
Clone or download
janicerar Merge pull request #1 from anderly/master
Add new static sortableRelations method with default.
Latest commit 56e7f96 Mar 11, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs Initial commit Oct 24, 2018
src Add new static sortableRelations method with default. Mar 9, 2019
.gitignore Initial commit Oct 24, 2018
README.md Initial commit Oct 24, 2018
composer.json Initial commit Oct 24, 2018

README.md

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.

You can’t perform that action at this time.