title: Undefined offset: 1 error issue when select from drop down list
body: <p>I write a function as below: and wonder why got this error? When the 
  <strong>cat_id and price selected</strong> is fine. <strong>Price selected</strong> also go well. Just when i choose only the <strong>Categories</strong> it doesn't any effect and show the error  <strong>Undefined offset: 1</strong></p>
  
  <pre><code>public function productsCat(Request $request){
      $cat_id = $request-&gt;cat_id;
      $price = explode("-",$request-&gt;price);
  
      $start = $price[0];
      $end = $price[1];
  
      if($cat_id!="" &amp;&amp; $price!="0"){
          $data = DB::table('products')
              -&gt;join('cats','cats.id','products.cat_id')
              -&gt;where('products.cat_id',$cat_id)
              -&gt;where('products.pro_price', "&gt;=", $start)
              -&gt;where('products.pro_price', "&lt;=", $end)
              -&gt;get();
  
      }
  
      else if($price!=""){
          $data = DB::table('products')
              -&gt;join('cats','cats.id','products.cat_id')
              -&gt;where('products.pro_price', "&gt;=", $start)
              -&gt;where('products.pro_price', "&lt;=", $end)
              -&gt;get();
      }
      else if($cat_id!=""){
          $data = DB::table('products')
              -&gt;join('cats','cats.id','products.cat_id')
              -&gt;where('products.cat_id',$cat_id)
              -&gt;get();
      }
      else{
          return "&lt;h1 align='center'&gt;Please select at least one filter from drop down list&lt;/h1&gt;";
  
      }
      if(count($data)=="0"){
          echo "&lt;h1 align='center'&gt;no products found under this Category&lt;/h1&gt;";
      }else{
          return view('front.productsPage',[
              'data' =&gt; $data, 'catByUser' =&gt; $data[0]-&gt;cat_name
          ]);
      }
  </code></pre>
  
  <p>}</p>