Using closure with sortable on TextColumn
I've set up my database schema using Eloquent models, and I'm trying to use the customer model in my sortable() method:
TextColumn::make('customer.postcode')
->sortable(query: function (Builder $query, string $direction): Builder {
return $query->whereHas('customer', function (Builder $q) use ($direction) {
$q->orderBy('postcode', $direction);
});
})
...however the sorting doesn't actually seem to work. It sorts the table records but not in any obvious order.
TextColumn::make('customer.postcode')
->sortable(query: function (Builder $query, string $direction): Builder {
return $query->whereHas('customer', function (Builder $q) use ($direction) {
$q->orderBy('postcode', $direction);
});
})
...however the sorting doesn't actually seem to work. It sorts the table records but not in any obvious order.