daily pastebin goal
28%
SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  public function update($id, Request $request)
  2.     {
  3.         $order = Order::findOrFail($id);
  4.        
  5.         $clientName = $request->input('client_name');
  6.         $warehouse = $request->input('warehouse');
  7.         $shipping = $request->input('shipping');
  8.         $phone = $request->input('client_phone');
  9.         $express = $request->input('express');
  10.         $awb = $request->input('awb');
  11.         $notes= $request->input('notes');
  12.        
  13.         $productName = $request->input('product_name');
  14.         $productSeries = $request->input('product_series');
  15.         $productQty = $request->input('product_qty');
  16.         $productPrice = $request->input('product_price');
  17.        
  18.         $order->client_name = $clientName;
  19.         $order->warehouse = $warehouse;
  20.         $order->shipping = $shipping;
  21.         $order->express = $express;
  22.         $order->awb = $awb;
  23.         $order->notes = $notes;
  24.         $order->client_phone = $phone;
  25.  
  26.         $totalOrder = 0;
  27.  
  28.         $order->products()->detach();
  29.         foreach($productName as $key => $product){
  30.  
  31.             $order->products()->attach($product, ['product_qty' => $productQty[$key], 'product_series' => $productSeries[$key]]);
  32.  
  33.             $order->products()->updateExistingPivot($product, ['product_price_two' => $productPrice[$key]]);
  34.  
  35.             $toUpdateProduct = Product::find($product);
  36.  
  37.             $toUpdateProduct->product_qty -= $productQty[$key];
  38.  
  39.             $toUpdateProduct->total_sold += $productQty[$key];
  40.  
  41.             $toUpdateProduct->save();
  42.  
  43.             $totalOrder += ($productPrice[$key] * $productQty[$key]);
  44.         }
  45.  
  46.         $order->total_order = $totalOrder;
  47.         $order->save();
  48.  
  49.         return redirect()->route('orders_list');
  50.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top