Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jacobcollinsdev's avatar

Query relationship absence after specific date

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?

0 likes
4 replies
Dunsti's avatar
Dunsti
Best Answer
Level 6

you can achieve this with a closure:

$absent_users = User::whereDoesntHave('activities', function ($query) {
		$query->where('date', '>=', '2022-10-01');
})->get();
1 like

Please or to participate in this conversation.