title: Laravel 5.6 Wherein with If condition
body: <p>My function in ProductRepository.php is like this :</p>
  
  <pre><code>public function listProductsFilter($columns=[],$category=[])
      {
          $keywords = [];
         foreach($columns as $key =&gt; $value){
           $keywords[] = [$key, 'LIKE', '%'.$value.'%'];
          }
  
           $query=  $this-&gt;model
           -&gt;join('category_product', 'products.id', '=', 'category_product.product_id')
            -&gt;orderBy('name', 'asc')
           -&gt;where('products.is_deleted', 0)
           -&gt;Where($keywords)
           -&gt;whereIn('category_product.category_id', $category)
           -&gt;get();
  
  
           return $query;
      }
  </code></pre>
  
  <p>I add a condition to check whether category exist or not. I tried to like it, but there comes error :</p>
  
  <pre><code>if(isset($category))
           -&gt;whereIn('category_product.category_id', $category)
  </code></pre>
  
  <p>syntax error, unexpected 'if' (T_IF)</p>
  
  <p>How can I solve the error?</p>