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
Assuming your business logic is correct, try using PHP instead of an SQL string in the where
clause:
$date = new DateTime;
$date->modify('-5 minutes');
$formatted_date = $date->format('Y-m-d H:i:s');
$result = DB::table('db_user')->where('id_user','=',Session::get('id_user'))->where('last_activity','>=',$formatted_date)->get();
Also, it is a good practice to always output the executed SQL queries just to make sure Laravel behaves as expected:
$queries = DB::getQueryLog();