title: Laravel tags with and query
body: <p>I have an product filter option .and user has product filters of different type in product category page.</p>
  
  <p><strong>Tags</strong></p>
  
  <pre><code>id | tag_name | slug |
  </code></pre>
  
  <p><strong>products</strong></p>
  
  <pre><code>id | proudct_name
  </code></pre>
  
  <p><strong>product_tags</strong> </p>
  
  <pre><code>id | product_id | tag_id 
  </code></pre>
  
  <p>Now am trying to retrieve all products where tag_name ="ddd" and tag_name="ddd".</p>
  
  <p>It means product should be in both the category .</p>
  
  <pre><code>$response=Product::with(['productCategory'])
  -&gt;when((isset($requestArray)&amp;&amp;count($requestArray)),function ($query)use($requestArray){
  
              $query-&gt;whereHas('productTags', function ($query) use ($requestArray) {
  
                  $query-&gt;where(function ($query) use ($requestArray){
  
                      if (isset($requestArray['filterForm'])&amp;&amp;count($requestArray['filterForm'])){
  
                          $valueArray=[];
                          foreach ($requestArray['filterForm'] as $key=&gt;$value){
  
  
                              if (is_array($value)&amp;&amp;count($value)){
  
  
                                 $query-&gt;whereIn('tags.slug',$value);
  
                              } elseif($key!="country_list"){
  
                                 $query-&gt;where('tags.slug',$value);
  
                              }
  
  
                          }
  
  
                      }
                  });
  
              });
          })
              -&gt;whereHas('productCategory',function ($query)use($request,$categoryName){
              $query-&gt;where('slug',$categoryName);
          });
  </code></pre>
  
  <p>I have issue when i select combination of mobile brand and mobile color/if i select only one filter group then it works fine</p>