title: whereHas query in Laravel
body: <p>Hello guys,</p>
  
  <pre><code>        $filterArray = explode("_", $filters);
  
          $data['articles'] = \DB::table('products')-&gt;join('product_category', function ($q) {
              $q-&gt;on('product_category.product_id', '=', 'products.id');
          })-&gt;where('product_category.category_id', '=', $id)
              -&gt;select('products.*')
              -&gt;whereBetween('price_retail_1', array($priceFrom, $priceTo))
              -&gt;whereHas('filters', function ($query, $filterArray) {
                  $query-&gt;whereIn('filter_id', $filterArray);
              })
              -&gt;orderBy('products.' . $sort, $sortOrder)
              -&gt;get();
      }
  </code></pre>
  
  <p>I have the following query and I'm having some issues on the whereHas method. I'm getting an error </p>
  
  <pre><code>Unknown column 'has' in 'where clause
  </code></pre>
  
  <p>most likely because the $filterArray variable is out of scope for the function ( or at least that is what I am guessing. Any help on how to solve the issue is appreciated.</p>