Laravel select records older than 5 minutes?

前端 未结 3 415
遥遥无期
遥遥无期 2021-02-05 21:58

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

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-05 22:23

    You can use whereRaw():

    $result = DB::table('db_user')->where('id_user','=',Session::get('id_user'))->whereRaw('last_activity >= now() - interval 5 minute')->get();
    

    or

    $result = DB::table('db_user')->where('id_user','=',Session::get('id_user'))->whereRaw('last_activity >= now() - interval ? minute', [5])->get();
    

提交回复
热议问题