Products::whereIn('category_id', ['223', '15', '20'])
->where('active', 1)
->get();
How can I fix this example so that it finds the exact occurrence of category_id = 223
and 15
and 20
and also necessarily active = 1
?
Products::whereIn('category_id', ['223', '15', '20'])
->where('active', 1)
->get();
How can I fix this example so that it finds the exact occurrence of category_id = 223
and 15
and 20
and also necessarily active = 1
?
2
Answers
It makes no sense to look for exactly
category_id = 15, 20 and 223
, it can only be one…But, if you still want that, your query is nearly there, you can do:
But, again, that should return an empty
Collection
.whereIn
is a simpleIN
in SQL, that means it is anOR
for all the values you want.Use from this group. Because, maybe you use
OR
condition in future. Therefore, your condition will not work correctly.For example
Explain of query above will work like that: