Laravel与联盟的关系

时间:2017-10-26 12:54:56

标签: php laravel

我有以下情况。 Employer模型有一个名为商品的方法:

public function offers()
{
    $offers = $this->hasMany(Offer::class)
        ->join('employers', 'offers.employer_id', '=', 'employers.id')
        ->join('recruiting_events', 'recruiting_events.id', '=', 'offers.recruiting_event_id');
    switch (request()->input('show')) {
        case 'future':
            $offers->where('recruiting_events.date', '<', DB::raw('NOW()'));
            break;
        case 'current':
        default:
            $offers->where('recruiting_events.date', '>=', DB::raw('NOW()'));
            break;
    }
    return $offers;
}

检查请求是否显示参数并根据它过滤数据。到目前为止,非常好 - Employer::find(1)->offers完美无缺。

但是,如果我想让所有有优惠的雇主得到一个SQL错误:

Employer::whereHas('offers')->get();

  

未找到列:1054未知列&#39; web_recruiting_events.date&#39;在&#39; where子句&#39; (SQL:选择count(*)作为web_employers中存在的聚合(选择*来自web_galleries其中web_galleriesgalleriable_id = web_employers。{{1} }和idweb_galleries = App \ Models \ Employer)并存在(从galleriable_type中选择* web_offersweb_offers = employer_idweb_employersidweb_recruiting_events&lt; NOW()和dateweb_offers为空))

为什么它不执行deleted_at子句,但join可以吗?

0 个答案:

没有答案