Skip to content

How can I retrieve all users that were inactive since date? #727

Answered by Gummibeer
moonvader asked this question in Q&A
Discussion options

You must be logged in to vote

If your user model uses this trait https://github.com/spatie/laravel-activitylog/blob/master/src/Traits/CausesActivity.php you can use the actions() relationship and use the created_at column.

$avtiveUsers = User::whereHas('actions', fn(Builder $q) => $q->where('created_at', '>=', now()->subWeek()))->get();

This will return all users with at least one activity in the last week. You can invert the whereHas() to get all inactive or change the carbon date to adjust the period to check.
It's a normal eloquent relationship so you can do whatever you want on the query.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Gummibeer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #727 on May 28, 2020 10:19.