title: Laravel select records older than 5 minutes?
body: <p>I have Laravel app where i check user loggedin regularly with a heartbeat for every 3 seconds (demo purpose, actually 5 minutes). For each beat I check if user's last activity with current time is also 5 minutes. If it is, log them out.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>$result = DB::table('db_user')-&gt;where('id_user','=',Session::get('id_user'))-&gt;where('last_activity','&gt;=',"now() - interval 5 minute")-&gt;get();
  
      if(!empty($result)) 
          return Redirect::to('/logout');
      else
          return Response::json('still-alive');
  </code></pre>
  
  <p>My problem is, this doesn't work. If I change the operand to <code>&lt;=</code>, it will log me out immediately before 5 minutes, if the operand is <code>&gt;=</code>, even after 5 minutes it won't log me out, can anyone explain why?</p>
  
  <p>-EDIT-</p>
  
  <p>Thanks for all the answers, I solved my problems by modifying my code to:</p>
  
  <pre><code>$result = DB::table('db_user')-&gt;where('id_user','=',Session::get('id_user'))-&gt;first();
  
      if(!empty($result)) 
          if(strtotime($result-&gt;last_activity) &lt; strtotime("-5 minutes"))
              return Redirect::to('/logout');
          else 
              return Response::json('still-alive');
      else
          return Response::json('no-record');
  </code></pre>