首页 > 解决方案 > Laravel 雄辩的查询以获取特定日期后仅用户的数据

问题描述

我有数据库表,有business_name 和user_id 以及created_at 和updated_at,现在我想查询数据,我将只获得那些user_ids 且只有created_at 大于特定日期的业务。

Business::where('created_at', '>' , new \DateTime('2020-08-30'))->distinct('user_id')->get();

现在这个查询返回 created_at 大于这个日期的记录,但我想要 user_id 只在此之后创建业务并且在此日期之前没有其他记录。

标签: phplaraveleloquent

解决方案


Business::whereRaw('MIN(created_at) > ' . new \DateTime('2020-08-30'))->distinct('user_id')->get();

推荐阅读