title: Foreach inner When query Laravel
body: <p>Hi Guys this is my function, i am using laravel 5.3</p>
  
  <pre><code>public function search(Request $request){
  
      $word = $request-&gt;search;
      $status = explode(",", $request-&gt;status);
      $type = explode(",", $request-&gt;type);
      $beds = $request-&gt;beds;
      $baths = $request-&gt;baths;
      $amenities = explode(",", $request-&gt;amenities);
      $typeCount = 0;
      $amenitiesCount = 0;
  
      $query = DB::table('properties as pr')
          -&gt;join('status as st', 'pr.status_id', '=', 'st.id')
          -&gt;join('types as ty', 'pr.type_id', '=', 'ty.id')
          -&gt;join('property_has_features as prfe', 'prfe.property_id', '=', 'pr.id')
          -&gt;join('features as fe', 'prfe.feature_id', '=', 'fe.id')
          -&gt;where('pr.title', 'like', '%'.$word.'%')
          -&gt;when($status, function ($query) use ($status) {
              $statusCount = 0;
              foreach ($status as $v) {
                  if ($statusCount &gt; 0){
                      return $query-&gt;orwhere('st.title', $v);
                  }
  
                  return $query-&gt;where('st.title', $v); 
                  ++$statusCount;
              }
          })-&gt;toSql();
  
      dd($query);
    }
  
  }
  </code></pre>
  
  <p>And i need to search for multiple values but if your search multiple fields i have a query to myqsl manual but now i am converting to laravel but the consult only make one where to st.title although the $status is a array with two values or more never make the if inner when, this is the consult i return for the debug, any help thanks</p>
  
  <pre><code>"select * from `properties` as `pr` inner join `status` as `st` on 
  `pr`.`status_id` = `st`.`id` inner join `types` as `ty` on 
  `pr`.`type_id` = `ty`.`id` inner join `property_has_features` 
  as `prfe` on `prfe`.`property_id` = `pr`.`id` inner join `features` 
  as `fe` on `prfe`.`feature_id` = `fe`.`id` where `pr`.`title` 
  like ? and `st`.`title` = ?"
  </code></pre>