Actually, I need to send the reminder emails to all my users in a time interval. So basically if a user has not posted any comment in last 3 days I need to send him the email.
I am using table structure:
Users
- id
- username
- unsubscribed
Comments
- id
- user_id
- comment
- created_at
I have used the silly query for that
Comment::with(['user' => function ($q) {
$q->where('unsubscribed', 0)->select('id', 'username', 'email');
}])
->groupBy('user_id')
->whereDate('created_at', $thereDaysAgoDate)
->get(['user_id']);
This give me all the users who have posted comment on that particular date.
My issue is, I only want the users who have posted a comment on that particular date but then not posted any comment after that date.
I can do this by fetching all users from comment table and then compare date via PHP if else condition but I do not want to approach in this manner.
So is there any way to achieve this via eloquent only.