[英]Laravel `Item` has many, return only if ALL are in the past
In my project, a hire
can have many hire_days
.在我的项目中,一个
hire
可以有很多hire_days
。 Each hire_day
is has a start
and end
timestamp.每个
hire_day
都有一个start
和end
时间戳。 I want to create a query where it will return only the hires where ALL of it's associated hire_day.end
times are in the past.我想创建一个查询,它只返回所有关联的
hire_day.end
时间都在过去的员工。 So far, my query:到目前为止,我的查询:
$hires = Hires::join('hires_days', function ($join) {
$join->on('hire_id', '=', 'hires.id');
})
->select('hires.id', 'hires.account_id', 'hires.job_number', 'hires.site_id', \DB::raw('MAX(end) AS end'))
->orderBy('hires_days.end', 'asc')
->groupBy('hires.id')
->paginate(10);
This will return hires
if at least one of their hire_days
is in the past, ignoring the fact that there are some associated hire_days
still in the future.如果他们的
hire_days
中至少有一个是过去的,这将返回hires
,忽略未来仍有一些相关的hire_days
这一事实。
我认为您需要的是添加到您的查询中:
->having('end', '<', time())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.