【发布时间】:2021-09-19 21:21:39
【问题描述】:
我正在使用 whereHas,我只想在子查询没有 NULL 时返回记录
return App\Bill_of_Lading::with('transactions.confirmed_transaction.delivery_order')
->whereHas('transactions.confirmed_transaction.delivery_order', function ($query) {
$query->whereNotNull('date_delivered');
})->get();
预期结果:NULL(因为有些交货单的 date_delivered 为 NULL) 结果:提单和空值交货单的集合
我也使用了 Laravel 的 "with" 没有成功
return App\Bill_of_Lading::with(['transactions.confirmed_transaction.delivery_order' => function($query){
$query->whereNotNull('date_delivered');
}])->get();
我什至将 whereNotNull 包裹在 where
return App\Bill_of_Lading::with('transactions.confirmed_transaction.delivery_order')
->whereHas('transactions.confirmed_transaction.delivery_order', function ($query) {
$query->where(function($q){
$q->whereNotNull('date_delivered');
});
})->get();
【问题讨论】: