F
Filament4mo ago
BBB

Sortable relation...

Hello everyone! This works:
Tables\Columns\TextColumn::make('user.lastname')->sortable()
Tables\Columns\TextColumn::make('user.lastname')->sortable()
This obviously does not work:
Tables\Columns\TextColumn::make('user.full_name')->sortable()
Tables\Columns\TextColumn::make('user.full_name')->sortable()
full_name is a combination of lastname and firstname. How should I proceed? Should I create a scope since it's in a relationship? Any help? Thanks in advance!
4 Replies
awcodes
awcodes4mo ago
Sounds like you need a virtual column. It’s somewhere in the docs. Sorry I don’t have a link at the moment.
BBB
BBB4mo ago
Yes, I've seen this solution, but I would prefer to first filter by last name and then by first name. Thank you for your response.
awcodes
awcodes4mo ago
Well, based on what your shared you don’t have a first or last name column. So it would have to be a virtual column.
BBB
BBB4mo ago
Actually, I don't know what got into me... I was foolish. All I needed to do was: Tables\Columns\TextColumn::make('user.full_name') ->sortable(['firstname', 'lastname']) Thank you 🙂