dimanche 21 juillet 2019

return redirect->back() inside DB::transaction()

I was trying to execute some statement inside DB::transaction method but the problem when a certain condition failed it should return redirect()->back()

But the problem is code neither redirect back nor getting executed further. What could be the possible reason for that?

  return DB::transaction(function ()  use ($request){ 
            $sellerItem = new SellerItem();
            $sellerItem->item_id = $request->item_id;
            $sellerItem->unit_price = $request->unit_price;
            $sellerItem->quantity = $request->quantity;
            $sellerItem->paid_amount = $request->paid_amount; 

            $sellerItem->payment_method = $request->payment_method;
            $sellerItem->seller_id = $request->seller_id;

            $sellerItem->due = ($request->unit_price*$request->quantity) + $request->due - $sellerItem->paid_amount; 
        //   dd($sellerItem);
            $sellerItem->before_due = $request->due;
 **Problem is in this block of statement**
            if($sellerItem->due<0)
            {

            return redirect()->back()->with('success', "Paid amount can't be greater than ".abs(($request->unit_price*$request->quantity) + $request->due)); 
            }

            $sellerItem->save();
            $item = Item::find($request->item_id);
            $item->quantity = $item->quantity+$request->quantity;
            $item->save();

            return redirect('item/stock-in');

              });



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire