F
Filamentβ€’10mo ago
Trauma Zombie

Is it possible to make searchable column on relation?

Hi guys, is it possible to search on table on relation?
Tables\Columns\TextColumn::make('clientable.name')
->label(__('Name'))
->icon(fn (Client $record) => match($record->clientable->getMorphClass()) {
'person' => 'heroicon-o-user',
'company' => 'heroicon-o-building-library',
})
->searchable(['clientable.name']),
Tables\Columns\TextColumn::make('clientable.name')
->label(__('Name'))
->icon(fn (Client $record) => match($record->clientable->getMorphClass()) {
'person' => 'heroicon-o-user',
'company' => 'heroicon-o-building-library',
})
->searchable(['clientable.name']),
2 Replies
SLy
SLyβ€’10mo ago
use something like: ->searchable(query: function (Builder $query, string $search): Builder { return $query ->whereRelation('relatedModel', 'name', 'like', '%' . $search . '%'); }),
Trauma Zombie
Trauma ZombieOPβ€’10mo ago
That works just fine. Thank you. πŸ™‚
Want results from more Discord servers?
Add your server