在我的项目中,一个hire
可以有很多hire_days
。每个hire_day
都有一个start
和end
时间戳。我想创建一个查询,其中它将仅返回过去所有时间都关联的hire_day.end
雇用。到目前为止,我的查询:
$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);
如果他们的hire_days
中至少有一项是过去的,这将返回hires
,忽略未来仍有一些相关hire_days
的事实。
我认为您需要添加到查询中:
->having('end', '<', time())