4.5.0
Added
- Sorting by
belongsTo
relationship:
Sometimes you may need to sort by a belongsTo
relationship. This become a breeze with Restify. Firstly you have to
instruct your sort to use a relationship:
// PostRepository
use Binaryk\LaravelRestify\Fields\BelongsTo;
use Binaryk\LaravelRestify\Filters\SortableFilter;
public static function sorts(): array
{
return [
'users.name' => SortableFilter::make()
->setColumn('users.name')
->usingBelongsTo(
BelongsTo::make('user', 'user', UserRepository::class),
)
];
}
Make sure that the column is fully qualified (include the table name).
The request could look like:
GET: /api/restify/posts?sort=-users.name
This will return all posts, sorted descending by users name.