public function updateOrder($id, Request $req) { if (isset($req['article_id'])) { $total = 0; //UPDATE DETAIL & CALCULATE TOTAL foreach ($req['article_id'] as $key => $article) { $detail = OrderDetails::firstOrCreate(['file_id' => $id, 'article_id' => $article]); $detail->price = $req["price"][$key]; $detail->quantity = $req["quantity"][$key]; $detail->save(); $total += $req["price"][$key] * $req["quantity"][$key]; $response[$req["supplier_id"][$key] . "-" . $article] = $detail->id; } //UPDATE TOTAL $order = Order::where(["file_id" => $id]); $order->update(['total_details_amount' => $total]); File::find($id)->touch(); } $stamp = date('d/m/Y, H:i:s'); return ["status" => "success", "new" => $response, "stamp" => $stamp, 'sum' => $total]; }