how can show users where last_seen column time <= 2 minutes with now()
i write this code but code cant calculate time
tip : last_seen column type is TimeStamp
$expiresAt = Carbon::parse(now())->addMinutes(2)->toTimeString();
$users = User::where('is_admin', '!=', 'superAdmin')->whereNotNull('last_seen')->whereTime('last_seen', '<=', $expiresAt)->orderBy('last_seen', 'DESC')->get();
CodePudding user response:
Try this code
$users = User::where('is_admin', '!=', 'superAdmin')
->whereNotNull('last_seen')
->whereDate('last_seen', '<=', now()->addMinutes(2))
->get();
It would be nice to have more information, are there any errors? show last_seen format
CodePudding user response:
ok i resolve this :D
wtf i must use subMinute now this code is true
$users = User::where('is_admin', '!=', 'superAdmin')
->whereNotNull('last_seen')
->whereTime('last_seen', '>=', now()->subMinute(2))
->get();