将多对where / where条件组合在一起

so here s the query i want

    $products = Product::whereHas('ProductFilter' , function($q) use ($filter_groups){

            foreach($filter_groups as $k=>$v)
            $q->where('f_id' , $k )->whereIn( 'value' ,$v );

        })->get();

which will result in this query

select * from `products` where exists 

( 
  select * from `product_filters` where 
 `product_filters`.`product_id` = `products`.`id` and 
 `f_id` = '4' and `value` in ('10', '11', '12', '13' )   and 
 `f_id` = '10' and `value` in ('34')

)

i want to group these line thoghether

 `f_id` = '4' and `value` in ('10', '11', '12', '13' )  
  and 
 `f_id` = '10' and `value` in ('34')

like

    ( `f_id` = '4' and `value` in ('10', '11', '12', '13' )   )
and 
    ( `f_id` = '10' and `value` in ('34') )

You can group your where clauses by nesting where() method calls so your example would look something like this:

$products = Product::whereHas('ProductFilter' , function($q) use ($filter_groups){
    foreach($filter_groups as $k=>$v) {
        $q->where(function (Builder $query) {
            $query->where('f_id', $k);
            $query->whereIn('value' ,$v );
        });
    })->get();

Here is the relevant section of the documentation.