Searchable Relationships in Tables

So if i have
Tables\Columns\TextColumn::make('user.name')
->label('Name')
->description(fn ($record) => $record->user->phone)
->searchable(),
Tables\Columns\TextColumn::make('user.name')
->label('Name')
->description(fn ($record) => $record->user->phone)
->searchable(),
, i cant simply add do ->searchable(['user.name','user.phone']) to add the phone field as a searchable attribute to it. Whats proper way to handle this?
5 Replies
Kenneth Sese
Kenneth Sese2y ago
Have you checked out this and it's not working?
TextColumn::make('full_name')
->searchable(query: function (Builder $query, string $search): Builder {
return $query
->where('first_name', 'like', "%{$search}%")
->where('last_name', 'like', "%{$search}%");
})
TextColumn::make('full_name')
->searchable(query: function (Builder $query, string $search): Builder {
return $query
->where('first_name', 'like', "%{$search}%")
->where('last_name', 'like', "%{$search}%");
})
Mark Chaney
Mark ChaneyOP2y ago
ah yes. no i remember. sucks we have to go through that trouble though wouldnt be an orwhere? nvm Actually it looks like you just use
->searchable(['name', 'email', 'phone'])
->searchable(['name', 'email', 'phone'])
so you just use the regular column names of that table
Kenneth Sese
Kenneth Sese2y ago
That's a lot easier!
Mark Chaney
Mark ChaneyOP2y ago
of that relationsihip lol, yep! yours doesnt look like a relationship though, so a little different case
Kenneth Sese
Kenneth Sese2y ago
That was just copy pasted from the docs It was mostly just to point out the closure in searchable All kind of little details like what you found in Filament that are neat!
Want results from more Discord servers?
Add your server