【发布时间】:2018-03-16 18:50:02
【问题描述】:
实际上,我需要在一个时间间隔内向我的所有用户发送提醒邮件。所以基本上如果用户在过去 3 天内没有发表任何评论,我需要向他发送电子邮件。
我正在使用表结构:
用户
- 身份证
- 用户名
- 电子邮件
- 退订
评论
- 身份证
- user_id
- 评论
- created_at
我为此使用了愚蠢的查询
Comment::with(['user' => function ($q) {
$q->where('unsubscribed', 0)->select('id', 'username', 'email');
}])
->groupBy('user_id')
->whereDate('created_at', $thereDaysAgoDate)
->get(['user_id']);
这给了我在该特定日期发表评论的所有用户。
我的问题是,I only want the users who have posted a comment on that particular date but then not posted any comment after that date。
我可以通过从comment 表中获取所有用户,然后通过 PHP 比较日期,如果其他条件,但我不想以这种方式接近。
那么有什么方法可以仅通过 eloquent 来实现。
【问题讨论】:
标签: php mysql laravel eloquent