title: How to get rid of too many if statements in laravel?
body: <p>I would like to create a more readable code by eliminating too many if statements but still does the job. I have tried creating a private method and extract the date range query and return the builder instance but whenever I do that, it does not return the correct builder query result so I end up smashing everything up on this method. </p>
  
  <p>Other parameters will be added soon, so the if statements would pill up very fast. :(</p>
  
  <p>Any tip on how to improve would be much appreciated. Thanks!</p>
  
  <pre><code>/**
   * @param array $params
   *
   * @param $orderBy
   * @param $sortBy
   *
   * @return Collection
   *
   * Sample:
   * `/orders?release_date_start=2018-01-01&amp;release_date_end=2018-02-20&amp;firm_id=3` OR
   * `/orders?claimId=3&amp;status=completed`
   *
   * Problem: Too many if statements
   *
   */
  public function findOrdersBy(array $params, $orderBy = 'id', $sortBy = 'asc'): Collection
  {
      $release_date_start = array_get($params, 'release_date_start');
      $release_date_end = array_get($params, 'release_date_end');
      $claimId = array_get($params, 'claimId');
      $firm_id = array_get($params, 'firm_id');
      $status = array_get($params, 'status');
  
      $orders = $this-&gt;model-&gt;newQuery();
  
      if (!is_null($release_date_start) &amp;&amp; !is_null($release_date_end)) {
          $orders-&gt;whereBetween('releaseDate', [$release_date_start, $release_date_end]);
      } else {
          if (!is_null($release_date_start)) {
              $orders-&gt;where('releaseDate', '&gt;=', $release_date_start);
          } else {
              if (!is_null($release_date_end)) {
                  $orders-&gt;where('releaseDate', '&lt;=', $release_date_end);
              }
          }
      }
  
      if (!is_null($claimId)) {
          $orders-&gt;where(compact('claimId'));
      }
  
      if (!is_null($firm_id)) {
          $orders-&gt;orWhere(compact('firm_id'));
      }
  
      if (!is_null($status)) {
          $orders-&gt;where(compact('status'));
      }
  
      return $orders-&gt;orderBy($orderBy, $sortBy)-&gt;get();
  }
  </code></pre>