Search in relationship from main model

I have a order resource, and the order model has orderProducts, hasMany, i want to be able to search in the order.orderProducts.name variable in the table of the order resource, how can i achieve this?
7 Replies
Dennis Koch
Dennis Koch2y ago
Did you try it with order.orderProducts.name already?
RobinDev
RobinDevOP2y ago
Then it does this
RobinDev
RobinDevOP2y ago
Dennis Koch
Dennis Koch2y ago
Okay. Thought it might be supported out of the box 😅
aj10144
aj101442y ago
Shouldn't it be orderProducts.name ?
BlackShadow
BlackShadow2y ago
You could custimize the query:
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}%");
})
make it work like that?

Did you find this page helpful?