F
Filamentβ€’16mo ago
RobinDev

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 Kochβ€’16mo ago
Did you try it with order.orderProducts.name already?
RobinDev
RobinDevOPβ€’16mo ago
Then it does this
RobinDev
RobinDevOPβ€’16mo ago
Dennis Koch
Dennis Kochβ€’16mo ago
Okay. Thought it might be supported out of the box πŸ˜…
aj10144
aj10144β€’16mo ago
Shouldn't it be orderProducts.name ?
BlackShadow
BlackShadowβ€’16mo 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?
Want results from more Discord servers?
Add your server