sortable() in second-level relationship

Currently, this resource is using ApplicationStatus model.
Tables\Columns\TextColumn::make("application.student.first_name")
->label("Student First Name")
->searchable()
->sortable(query: function (Builder $query, string $direction): Builder {
return $query->whereHas('application.student', function($sQuery) use ($direction) {
return $sQuery->orderBy('first_name', $direction);
});
}),
Tables\Columns\TextColumn::make("application.student.first_name")
->label("Student First Name")
->searchable()
->sortable(query: function (Builder $query, string $direction): Builder {
return $query->whereHas('application.student', function($sQuery) use ($direction) {
return $sQuery->orderBy('first_name', $direction);
});
}),
Since the default sortable() is not working, so I had to customize the query to it. However, the one I made is not working.
1 Reply
vahnmarty
vahnmartyOP9mo ago
I fixed this by updating my ListRecord Resource, ListApplicationStatuses.php
protected function getTableQuery(): Builder
{
return ApplicationStatus::join('applications', 'application_status.application_id', 'applications.id');
}
protected function getTableQuery(): Builder
{
return ApplicationStatus::join('applications', 'application_status.application_id', 'applications.id');
}
Want results from more Discord servers?
Add your server