F
Filamentβ€’12mo 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β€’12mo ago
Did you try it with order.orderProducts.name already?
RobinDev
RobinDevβ€’12mo ago
Then it does this
RobinDev
RobinDevβ€’12mo ago
Dennis Koch
Dennis Kochβ€’12mo ago
Okay. Thought it might be supported out of the box πŸ˜…
aj10144
aj10144β€’12mo ago
Shouldn't it be orderProducts.name ?
BlackShadow
BlackShadowβ€’12mo 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?