Laravel`Item`有很多,只有ALL过去才会返回

时间:2016-04-28 11:23:34

标签: php mysql laravel

在我的项目中,hire可以包含多个hire_days。每个hire_day都有一个startend时间戳。 我想创建一个查询,在该查询中,它只会返回过去所有与之关联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);

如果他们hires中至少有一个人过去,则会返回hire_days,而忽略了以后还有一些关联hire_days的事实。

1 个答案:

答案 0 :(得分:1)

我认为您需要的是添加到您的查询中:

->having('end', '<', time())