1 回答
TA贡献2039条经验 获得超7个赞
解决这个问题的一种方法是使用 Facade 而不是闭包。
例如,使用您的代码:
DB::beginTransaction();
$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;
$sellerItem->before_due = $request->due;
if ($sellerItem->due < 0) {
DB::rollBack();
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();
DB::commit();
return redirect('item/stock-in');
- 1 回答
- 0 关注
- 270 浏览
添加回答
举报