mohammad6006
2 years ago

intersect sub query

Posted 2 years ago by mohammad6006

I want to filter my products page there is a filter table and filter_product table with many to many relation with product table

my filters table is like this:

-id
-parent_id
-name

//filters with same parent_id shoud be OR in filtering and the result of that shoud be AND with different parent id filtering

filter_product

-product_id
-filter_id

for example I want to filter product by color and size

color: -red -green

size: -large -xlarge

(red OR green ) AND (large OR xlarg) how can do that?

its the code that I write And I want to know how can i get intersect result of two sub query

Product::with('filters)
->whereHas('filters' , function ($query){

$query->whereIn('filter_id',$array1);
intersect 
$query->whereIn('filter_id',$array2);
}

Please sign in or create an account to participate in this conversation.