You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I can't find anything in the docs about sorting by a join or scope.
So I would say you will have to tinker with it. But I will also check if I find a way.
Got it!
First on spatie's query builder add one or many custom sort:
use Spatie\QueryBuilder\Sort;
...
->allowedSorts(Sort::custom('name', new BookSort(), 'name', Sort::custom('description', new BookSort(), 'description')
Then create a class:
use Illuminate\Database\Eloquent\Builder;
use Spatie\QueryBuilder\Sorts\Sort;
class BookSort implements Sort
{
public function __invoke(Builder $query, $descending, string $property) : Builder
{
return $query->OrderByTranslation($property, $descending ? 'desc' : 'asc');
}
}
Has anyone tried using translatable with spatie/laravel-query-builder ?
If so, how can I sort by translation fields?
Thanks
The text was updated successfully, but these errors were encountered: