Exemplo n.º 1
0
 public function updateRepair($id, Request $req)
 {
     if (isset($req['article_id'])) {
         $total = 0;
         //UPDATE DETAIL & CALCULATE TOTAL
         foreach ($req['article_id'] as $key => $article) {
             $detail = RepairDetails::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["art-" . $article] = $detail->id;
         }
         //UPDATE TOTAL
         $repair = Repair::where(["file_id" => $id]);
         $repair->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];
 }