title: Multiple conditional where clauses not working in Eloquent query
body: <p>I have a function that is supposed to use a combination of filters set by the user to fetch information from a table (or no filters at all).</p>
  <p>Keep in mind I'm not trying to override filters here, the query should dynamically add or remove filters depending on the ones set client-side by the user.</p>
  <p>The filters work well individually, but when setting multiple of them, the query doesn't fetch the correct data at all. I'm still unable to figure out what the criteria for the incorrect data being fetched is.</p>
  <p>The only filters that seem to work in combination with others are <code>date_from</code> and <code>date_to</code>.</p>
  <p>This is the function:</p>
  <pre><code>public function getReport(Request $request)
  {
      // Convertir fechas a formato correcto
      $request-&gt;date_from = date('Y-m-d', strtotime(str_replace('-', '/', $request-&gt;date_from)));
      $request-&gt;date_to = date('Y-m-d', strtotime(str_replace('-', '/', $request-&gt;date_to)));
      
      $query = Ticket::all();
  
      $query-&gt;when(isset($request-&gt;date_from), function ($q) use ($request) {
          return $q-&gt;where('date_created', '&gt;=', $request-&gt;date_from);
      });
      $query-&gt;when(isset($request-&gt;date_to), function ($q) use ($request) {
          return $q-&gt;where('date_created', '&lt;=', $request-&gt;date_to);
      });
      $query-&gt;when(isset($request-&gt;user), function ($q) use ($request) {
          return $q-&gt;where('user', $request-&gt;user);
      });
      $query-&gt;when(isset($request-&gt;paid), function ($q) use ($request) {      
          if ($request-&gt;paid === true) {
              return $q-&gt;whereNotNull('paid');
          } else {
              return $q-&gt;whereNull('paid');
          }
      });
      $query-&gt;when(isset($request-&gt;informed), function ($q) use ($request) {       
          return $q-&gt;where('informed', $request-&gt;informed);
      });
      $query-&gt;when(isset($request-&gt;endorsement), function ($q) use ($request) {       
          if ($request-&gt;endorsement === true) {
              $query-&gt;where('policy', '&lt;', 1);
          } else {
              $query-&gt;where('policy', '&gt;', 1);
          }
      });
      $query-&gt;when(isset($request-&gt;duplicate), function ($q) use ($request) {       
          return $q-&gt;where('duplicate', $request-&gt;duplicate);
      });
      $query-&gt;when(isset($request-&gt;active), function ($q) use ($request) {        
          return $q-&gt;where('active', $request-&gt;active);
      });
      
      return response()-&gt;json($query, $this-&gt;success_status);
  }
  </code></pre>
  <p>I've tested the <code>$request</code> payload multiple times and there's no issues with the information coming client-side.</p>
  <p>What am I doing wrong?</p>