Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function update(Order $order)
- {
- $attributes = $this->validateOrder();
- $order->update($attributes);
- $products = \request('products');
- $quantity = \request('quantity');
- $price = \request('price');
- $discount = \request('discount');
- $total = 0;
- $previousPivot = DB::table('order_product')->where('order_id', $order->id)->get();
- // Check if products exists
- if($products) {
- $order->products()->detach();
- foreach($products as $key => $value) {
- $attributes = [
- 'price' => $price[$key],
- 'quantity' => $quantity[$key],
- 'discount' => $discount[$key],
- ];
- $order->products()->attach($value, $attributes);
- $toUpdateProduct = Product::findOrFail($value);
- $previousPivotProduct = $previousPivot->where('product_id', 2);
- if($previousPivotProduct) {
- dd($previousPivotProduct->first()->quantity);
- $previousQty = $previousPivotProduct->first()->quantity;
- dd($previousQty);
- }
- }
- }
- $this->flashMessage('success', 'Your order was updated with success!');
- return redirect()->back();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement