3 回答
TA贡献2012条经验 获得超12个赞
你可以whereDate这样使用:
$users = User::whereHas('address', function ($q) {
$q->whereDate('created_at', '>', Carbon::now()->subDays(7));
})->get();
TA贡献1934条经验 获得超2个赞
你可以试试这样
$user = User::where('address',date('Y-m-d', strtotime('-7 days')))->where('created_at',date('Y-m-d', strtotime('-7 days')))->get();
TA贡献1876条经验 获得超6个赞
使用注释更改您的代码
$users = User::whereHas('address', function ($q): void {
$q->where(function ($query): void {
/**
* Subqueries use Eloquent Builder class here to add some wrapped filters
* But your code takes all addresses, filter them for nothing
* You should add SQL filters to builder something like that:
**/
$query->whereDate(Carbon::now()->subDays(7), '<', 'created_at');
})
/** To get users by your filters */
->get();
- 3 回答
- 0 关注
- 117 浏览
添加回答
举报