title: How can I filter a negative value from a query made with eloquent and then paginate it?
body: <p>I was trying to get the remaining time for movie delivery in a rental system made with laravel.
  I built the following query using eloquent and it returned the result I wanted:</p>
  <pre><code>        $resting_time = DB::table('alquiler')
                      -&gt;join('socio','alquiler.soc_id','=','socio.id')
                      -&gt;join('pelicula','alquiler.pel_id','=','pelicula.id')
                      -&gt;select('socio.soc_nombre','pelicula.pel_nombre','alquiler.created_at', DB::raw(&quot;DATEDIFF(alq_fecha_hasta,NOW()) AS Days&quot;))
                      -&gt;orderBy('Days','asc')
                      -&gt;paginate(6);
  </code></pre>
  <p><a href="https://i.stack.imgur.com/HvxRh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HvxRh.png" alt="Result" /></a></p>
  <p>but there is a problem when these rentals go over the delivery deadline it returns negative values, so I would like the query to return only the rentals that have the remaining days greater than zero and then paginate those results.</p>
  <p>I create this statement and using map() filter only the positives that are returned in a collection but the problem is that I can't paginate them.</p>
  <pre><code>$resting_time = DB::table('alquiler')
                      -&gt;join('socio','alquiler.soc_id','=','socio.id')
                      -&gt;join('pelicula','alquiler.pel_id','=','pelicula.id')
                      -&gt;select('socio.soc_nombre','pelicula.pel_nombre','alquiler.created_at', DB::raw(&quot;DATEDIFF(alq_fecha_hasta,NOW()) AS Days&quot;))
                      -&gt;get()-&gt;map(function($alquiler){
                          return ($alquiler-&gt;Days &gt;= 0) ? $alquiler : null;
                      });
  $resting_time = $resting_time-&gt;filter()-&gt;sortBy('Days');
  </code></pre>
  <p>This is the returning collection:</p>
  <p><a href="https://i.stack.imgur.com/o7r8c.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/o7r8c.png" alt="enter image description here" /></a></p>
  <p>But this type of collection cannot be paginated.</p>
  <p><a href="https://i.stack.imgur.com/SUH7k.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SUH7k.png" alt="enter image description here" /></a></p>
  <p>Any idea how to fix it, or maybe an easier way to do it? Sorry if something doesn't make sense, I'm just starting in laravel.</p>