this problem killing me
I have store method and it work well and when create one, table update increase quantity correctly. but when I delete that Item which I’m created the table doesn’t update at all, and it most decrease the quantity
$products = $request->items;
for ($i = 0; $i < count($products); $i++) {
$billProduct = new BillProduct();
$billProduct->bill_id = $bill->id;
$billProduct->product_id = $products[$i]['item'];
$billProduct->quantity = $products[$i]['quantity'];
$billProduct->save();
Utility::total_quantity('plus',$billProduct->quantity,$billProduct->product_id);
and this is destroy controller
if ($bill->created_by == Auth::user()->creatorId()) {
$bill->delete();
if ($bill->vender_id != 0) {
Utility::userBalance('vendor', $bill->vender_id, $bill->getTotal(), 'debit');
}
BillProduct::where('bill_id', '=', $bill->id)->delete();
and this is model which – or + quantity
Utility::total_quantity('plus',$billProduct->quantity,$billProduct->product_id);
Utility::total_quantity('munis',$billProduct->quantity,$billProduct->product_id);
how can I fix this problem in destroy??when I put the minus code in destroy methods get server error500.
thank you for help