joligoms / nova-sort-relations
This package improves support for sorting relations in Laravel Nova.
Installs: 16
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 7
pkg:composer/joligoms/nova-sort-relations
Requires
- php: >=7.1.0
This package is auto-updated.
Last update: 2025-12-17 23:04:32 UTC
README
This package improves support for sorting relations in Laravel Nova.
Installation
Install via composer
$ composer require joligoms/nova-sort-relations
Usage
Include Joligoms\SortRelations\SortRelations trait to your resource class or in App\Nova\Resource if you want all resources to have this feature. Define sortable columns in $sortRelations array.
... use Joligoms\SortRelations\SortRelations; ... class Post extends Resource { public static $sortRelations = [ 'user' => /* The attribute specified in the field, for example: ˅˅˅˅ Text::make(__('User'), 'user', function () { return $this->model()->user->username; }); */ [ 'relation' => 'user', // The relation from the current resource's model. 'title' => 'username', // (Optional) The relation's column that should be selected in the indexQuery. If not specified, it will use the resource's title property. 'columns' => 'username' // The columns that should be ordered in the query. It can be a string or array. ], 'company' => [ 'relation' => 'user.company', // Dot notation can be specified when the relation goes through multiple relations. 'columns' => 'name' ] ]; public static function indexQuery(NovaRequest $request, $query) { // You can modify your base query here, only if necessary. Sort Relations will be applied automatically... 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.