I'm using whereHas and I only want to return the records if sub query has no 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();
Expected result: NULL (because there are delivery orders that have NULL date_delivered) Result: The collection of Bill of Ladings together with the delivery orders with NULL values
I also used Laravel's "with" with no success
return App\Bill_of_Lading::with(['transactions.confirmed_transaction.delivery_order' => function($query){
$query->whereNotNull('date_delivered');
}])->get();
I even wrapped the whereNotNull inside 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();