How to sort TextColumn by relationship date attribute?

Im trying it in 2 diff ways, both doesnt work:
Tables\Columns\TextColumn::make('ticketingRateGamesPivot.game.game_date')
->label(__('Game date'))
->date('d/m/Y H:i')
->sortable() // <- first way
// second way:
// ->sortable(query: function (Builder $query, string $direction): Builder {
// return $query->whereHas('ticketingRateGamesPivot', function ($q) use ($direction) {
// $q->whereHas('game', function ($q2) use ($direction) {
// $q2->orderBy('game_date', $direction);
// });
// });
// })
Tables\Columns\TextColumn::make('ticketingRateGamesPivot.game.game_date')
->label(__('Game date'))
->date('d/m/Y H:i')
->sortable() // <- first way
// second way:
// ->sortable(query: function (Builder $query, string $direction): Builder {
// return $query->whereHas('ticketingRateGamesPivot', function ($q) use ($direction) {
// $q->whereHas('game', function ($q2) use ($direction) {
// $q2->orderBy('game_date', $direction);
// });
// });
// })
* not using admin panel in first way i get this error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'ticketing_rate_games.game_id' in 'where clause'
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'ticketing_rate_games.game_id' in 'where clause'
in second way: doesnt crash but it just doesnt sort it
6 Replies
ericmp #2
ericmp #2OP17mo ago
i also tried this way:
->sortable(query: function (Builder $query, string $direction): Builder {
return $query->with(['ticketingRateGamesPivot.game' => function ($query) use ($direction) {
$query->orderBy('game_date', $direction);
}]);
->sortable(query: function (Builder $query, string $direction): Builder {
return $query->with(['ticketingRateGamesPivot.game' => function ($query) use ($direction) {
$query->orderBy('game_date', $direction);
}]);
doesnt work, doesnt crash if someone replies, id appreciate @ me please
Mark Chaney
Mark Chaney16mo ago
@joe did you figure this out? sortable() doesnt allow closure, right?
Mark Chaney
Mark Chaney16mo ago
GitHub
filament/packages/tables/src/Columns/Concerns/CanBeSortable.php at ...
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
ericmp #2
ericmp #2OP16mo ago
thanks for @ me, nah, didnt figured it out, just made it not sortable :/ np
Mark Chaney
Mark Chaney16mo ago
yep. I wasnt able to get it working with a closure either. I will try ot let you know if i figure it out though. Wish it was more straight forward
ericmp #2
ericmp #2OP16mo ago
okayy, thanks. @ me if so please (:
Want results from more Discord servers?
Add your server