我试图在DB::transaction方法中执行一些语句,但是当某个条件失败时应该出现问题return redirect()->back()
但问题是代码既没有重定向回来也没有进一步执行。可能的原因是什么?
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');
});
largeQ