multiples where are AND where
Your probably want to use orWhere
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am trying to query categories where product tags is equal to user selected tags in filter bar , Here is the query what I have tried so far :
$categories = Category::with('products');
// selected tags is array which contain tags
if (! empty($selectedTags)) {
foreach ($categories->get() as $category) {
$categories = $category->whereHas('products', function ($query) use ($selectedTags) {
foreach ($selectedTags as $tag) {
$query->where('tags','LIKE','%'.$tag.'%');
}
});
}
}
$categories = $categories->distinct()->paginate(3);
Please note that tags column in product table is comma separated values that's why I am trying to access it via like query .
Please or to participate in this conversation.