I have a Order model and a Transaction model. A order can have one or multiple transactions.
I want those orders whose every transactions status are 'Pending'.
I tried to implement like below:
$builder = Order::with('transactions')->latest('id');
if(condition)
{
$builder->whereHas('transactions', function ($query) {
$query->where('status', 'Pending');
});
}
This returns those order whose at least one transaction has 'Pending' status. But I want those orders whose every transactions have status 'Pending'.