you can achieve this with a closure:
$absent_users = User::whereDoesntHave('activities', function ($query) {
$query->where('date', '>=', '2022-10-01');
})->get();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a users table and a activity_log table. When a user logs in/out, a record is created in the activity_log table.
How can I query users that have had no activity after a certain date? I know I can do:
$absent_users = User::whereDoesntHave('activities')->get();
How can I expand on this to say "return users with no activity logs after 2022-10-01", for example?
you can achieve this with a closure:
$absent_users = User::whereDoesntHave('activities', function ($query) {
$query->where('date', '>=', '2022-10-01');
})->get();
Please or to participate in this conversation.