F
Filament7mo ago
Neamix

Search my mutators

Hello,i have 2 models User and Pet Each pet belongs to a user and each user have firstname and surname so in table pet i displayed user full name using mutator so i want to know if there is any method to allow user to search by mutator
1 Reply
Neamix
NeamixOP7mo ago
So i used that solutions after i found that searchable can get clousre
Tables\Columns\TextColumn::make('pet.name')
->numeric()
->sortable(),
Tables\Columns\TextColumn::make('pet.user.full_name')
->label('Owner Full Name')
->searchable(query: function ($query,$search) {
$query->whereHas('pet.user',function ($subQuery) use ($search) {
$subQuery->where('firstname','like','%'.$search.'%')
->orWhere('surname','like','%'.$search.'%');
});
}),
Tables\Columns\TextColumn::make('pet.name')
->numeric()
->sortable(),
Tables\Columns\TextColumn::make('pet.user.full_name')
->label('Owner Full Name')
->searchable(query: function ($query,$search) {
$query->whereHas('pet.user',function ($subQuery) use ($search) {
$subQuery->where('firstname','like','%'.$search.'%')
->orWhere('surname','like','%'.$search.'%');
});
}),
but still i need to know if that is the best solution or there is something better
Want results from more Discord servers?
Add your server