How to use condition with query builder

Viewed 93

I have orders table which contains status, paymode, pay_status column

I want to get order if paymode is cod then pay_status unconfirmed can get
and
if paymode is payu then pay_status only confirmed can get

Here I tried with whereRaw

$orders = Order::whereHas('products', function (Builder $query) use ($seller) {
            $query->where('seller_id', $seller->id);
        })
            ->whereRaw('IF (`paymode` = `payu`, `pay_status` = `confirmed`)')
            ->paginate(25);

but it's not working

1 Answers

you can try like this also for multiple conditions

 $orders = Order::whereHas('products', 
    function (Builder $query) use ($seller) { 
         $query->where('seller_id', $seller->id); 
    })->whereRaw('paymode = ? AND pay_status = ?', ['payu','confirmed']) 
      ->orWhereRaw('paymode = ? AND pay_status = ?', ['cod','unconfimed ']) 
    ->paginate(25); 
Related