Sort by Attribute

I have an attribute called age that gets the age of the user calculated by their DOB, how can I create a sortable on this column.
2 Replies
datarecall
datarecallOP15mo ago
@Leandro Ferreira That sorts by the column itself not by an attribute, i thought about trying to figure out a way to srt by DOB while showing the age but couldnt figure it out I guess you could do something like
->sortable(query: function (Builder $query, string $direction): Builder {
return $query
->orderBy('last_name', $direction)
->orderBy('first_name', $direction);
})
->sortable(query: function (Builder $query, string $direction): Builder {
return $query
->orderBy('last_name', $direction)
->orderBy('first_name', $direction);
})
TextColumn::make('age')
->sortable(query: function (Builder $query, string $direction): Builder {
return $query
->orderBy('dob', $direction);
}),
TextColumn::make('age')
->sortable(query: function (Builder $query, string $direction): Builder {
return $query
->orderBy('dob', $direction);
}),
should do the trick
Want results from more Discord servers?
Add your server