这种写法不正确,‘notice_cad’ function里面有带条件whereIn,外面要加一层whereHas
$data = ProofingNotice::with(['notice_cad' => function ($qn) {
$qn->with(['user_name'])->whereIn('flag', [4]);
}, 'exploit' => function ($qs) {
$qs->with(['client', 'brand', 'devedep', 'deveaids', 'client_branch']);
}, 'notice_cad_review', 'colors'])
->whereIn('status', $arr_status)
->whereIn('area_id', $place_from)
->whereBetween('review_date', [$start_date, $end_date])
->get()->toArray();
上面的写法应改为:
$data = ProofingNotice::with(['notice_cad'=>function($w){
$w->with(['user_name'])->whereIn('flag', [4]);
}, 'exploit', 'colors','notice_cad_review'])
->whereHas('notice_cad', function ($qn) {
$qn->with(['user_name'])->whereIn('flag', [4]);
})
->whereHas('exploit', function ($qs) {
$qs->with(['client', 'brand', 'devedep', 'deveaids', 'client_branch']);
})
->whereIn('status', $arr_status)
->whereIn('area_id', $place_from)
->where(function ($qd) use ($start_date, $end_date) {
$qd->whereBetween('nuclear_date', [$start_date, $end_date]);
$qd->orwhereBetween('transport_date', [$start_date, $end_date]);
})->get()->toArray();
别问为什么,不知道