这种写法不正确,‘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();
别问为什么,不知道
一、
$data = ProofingNotice::with(['notice_cad'=>function($w){
$w->with(['user_name'])->whereIn('flag', [12])->where(['state'=>0]);
}, 'exploit', 'colors','notice_cad_review'])
->whereHas('notice_cad', function ($qn) {
$qn->with(['user_name'])->whereIn('flag', [12])->where(['state'=>0]);
})
->whereHas('exploit', function ($qs) {
$qs->with(['client', 'brand', 'devedep', 'deveaids', 'client_branch']);
})
->whereIn('status', $arr_status)
->whereIn('area_id', $place_from)
->where('properties_id','<>',15) //15局部样
->where(function ($qd) use ($start_date, $end_date) {
$qd->whereBetween('review_date', [$start_date, $end_date]);
})->get()->toArray();
二、
$data = ProofingNotice::with(['notice_size',
'exploit'=>function($qe) use($depid,$client_id,$brand_id,$deve_aid){
if (isset($depid)){
$qe->with(['client','brand','devedep','deveaids','client_branch'])
->whereIn('deve_dep',$depid);
}
if (isset($client_id)){
$qe->with(['client','brand','devedep','deveaids','client_branch'])
->where('client_id',$client_id);
}
if (isset($brand_id)){
$qe->with(['client','brand','devedep','deveaids','client_branch'])
->where('brand_id',$brand_id);
}
if (isset($deve_aid)){
$qe->with(['client','brand','devedep','deveaids','client_branch'])
->where('deve_aid',$deve_aid);
}
if( !isset($depid) && !isset($client_id) && !isset($brand_id) && !isset($deve_aid) ) {
$qe->with(['client','brand','devedep','deveaids','client_branch']);
}
},
'colors'=>function($qc) use($place_id){
if (isset($place_id)) {
$qc->where(['place_id' => $place_id]);
}
}
])
->whereHas('exploit', function ($qe) use($depid,$client_id,$brand_id,$deve_aid) {
if (isset($depid)){
$qe->with(['client','brand','devedep','deveaids','client_branch'])
->whereIn('deve_dep',$depid);
}
if (isset($client_id)){
$qe->with(['client','brand','devedep','deveaids','client_branch'])
->where('client_id',$client_id);
}
if (isset($brand_id)){
$qe->with(['client','brand','devedep','deveaids','client_branch'])
->where('brand_id',$brand_id);
}
if (isset($deve_aid)){
$qe->with(['client','brand','devedep','deveaids','client_branch'])
->where('deve_aid',$deve_aid);
}
if( !isset($depid) && !isset($client_id) && !isset($brand_id) && !isset($deve_aid)) {
$qe->with(['client','brand','devedep','deveaids','client_branch']);
}
})
->whereHas('colors',function ($qc) use($place_id){
if (isset($place_id)) {
$qc->where(['place_id' => $place_id]);
}
})
->whereIn('status',$arr_status)
->whereIn('area_id',$place_from)
->whereIn('properties_id',$arr_properties)
->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();