Sortable with nested relations
How can I use sortable with multiple relations?
when I try to sort type.year.name it gives me :
Column not found: 1054 Unknown column 'pk_types.year_id'
which is normal because there's no column year_id in table regions
5 Replies
you would need to pass a custom sortable query function
in v3 it is fixed.
Is this a good start?
->sortable(query: function (Builder $query, string $direction): Builder {
return $query
->orderBy('last_name', $direction)
->orderBy('first_name', $direction);
})
yeah but you need to work out how to sort on a deeply nested relationship
its tricky with Eloquent
Could something like this work?
i doubt you need the select