PHP code example of lifeonscreen / nova-sort-relations
1. Go to this page and download the library: Download lifeonscreen/nova-sort-relations library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lifeonscreen / nova-sort-relations example snippets
...
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;
}
}