在我的项目中,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
仍然存在的事实 future 。
最佳答案
我认为您需要的是添加到您的查询中:
->having('end', '<', time())
关于php - Laravel `Item` 有很多,只有在过去时才返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36913165/