title: how to simplify if elseif statement to get particular search data from laravel MySQL database
body: <p>I am collecting all the data like id, name, date, empid from the controller in variable data</p>
  <pre><code>$data = $request-&gt;all();
  
  </code></pre>
  <p>now i want to select all the rows from the mysql table base on the input value i receive from request like this.</p>
  <p>if no value is given then select all from DB</p>
  <pre><code>if ($data['keyvalue'] == '' &amp;&amp; $data['datefrom'] =='' &amp;&amp; $data['dateto'] =='' &amp;&amp; $data['prepid'] =='' ){
  
             $country =  country::get(); 
  
  </code></pre>
  <p>if only certain input value is given</p>
  <pre><code>elseif ($data['keyvalue'] !== '' &amp;&amp; $data['datefrom'] =='' &amp;&amp; $data['dateto'] =='' &amp;&amp; $data['prepid'] =='' ){
  
              $country = country::where('sr_status','LIKE','%'.$data['status'].'%')
                      -&gt;Where('sr_name','LIKE','%'.$data['keyvalue'].'%')
                      -&gt;orWhere('tel_code','LIKE','%'.$data['keyvalue'].'%')
                      -&gt;orWhere('country_code','LIKE','%'.$data['keyvalue'].'%')
                      -&gt;orWhere('currency_name','LIKE','%'.$data['keyvalue'].'%')
                      -&gt;orderBy('sr_id')
                      -&gt;get();
  
  }elseif ($data['keyvalue'] == '' &amp;&amp; $data['datefrom'] !=='' &amp;&amp; $data['dateto'] =='' &amp;&amp; $data['prepid'] =='' ){
  
              $country = country::where('sr_status','LIKE','%'.$data['status'].'%')
                      -&gt;whereDate('created_at','&gt;=',$data['datefrom'])
                      -&gt;orderBy('sr_id')
                      -&gt;get();
  
  }elseif ($data['keyvalue'] == '' &amp;&amp; $data['datefrom'] =='' &amp;&amp; $data['dateto'] !=='' &amp;&amp; $data['prepid'] =='' ){
  
              $country = country::where('sr_status','LIKE','%'.$data['status'].'%')
                      -&gt;whereDate('created_at','&lt;=',$data['dateto'])
                      -&gt;orderBy('sr_id')
                      -&gt;get();  
  
  }elseif ($data['keyvalue'] == '' &amp;&amp; $data['datefrom'] =='' &amp;&amp; $data['dateto'] =='' &amp;&amp; $data['prepid'] !=='' ){
  
              $country = country::where('sr_status','LIKE','%'.$data['status'].'%')
                      -&gt;Where('prep_emp','LIKE','%'.$data['prepid'].'%')
                      -&gt;orderBy('sr_id')
                      -&gt;get();   
                      
  }
  
  </code></pre>
  <p>and if all input value is given</p>
  <pre><code>elseif ($data['keyvalue'] !== '' &amp;&amp; $data['datefrom'] !=='' &amp;&amp; $data['dateto'] !=='' &amp;&amp; $data['prepid'] !=='' ){ 
  
             $country = country::where('sr_status','LIKE','%'.$data['status'].'%')
                      -&gt;whereDate('created_at','&gt;=',$data['datefrom'])
                      -&gt;whereDate('created_at','&lt;=',$data['dateto'])
                      -&gt;Where('sr_name','LIKE','%'.$data['keyvalue'].'%')
                      -&gt;orWhere('tel_code','LIKE','%'.$data['keyvalue'].'%')
                      -&gt;orWhere('country_code','LIKE','%'.$data['keyvalue'].'%')
                      -&gt;orWhere('currency_name','LIKE','%'.$data['keyvalue'].'%')
                      -&gt;Where('prep_emp','LIKE','%'.$data['prepid'].'%')
                      -&gt;orderBy('sr_id')
                      -&gt;get();
  }
  
  </code></pre>
  <p>everything working fine i just want to simplify this code..</p>