Advertisement
bang_diba

Update Cart Laravel

Jul 21st, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.60 KB | None | 0 0
  1. public function update(Request $request)
  2.     {
  3.         $price_product      = $request->price_product;
  4.         $qty_cart           = $request->qty_cart;
  5.         $price_cart         = $qty_cart * $price_product;
  6.  
  7.         foreach ($request->cart_id as $d => $cartId) {
  8.             $data = Cart::where('cart_id', $cartId)->update([
  9.                 'qty_cart'      => $request->qty_cart,
  10.                 'price_cart'    => $price_cart,
  11.  
  12.             ]);
  13.  
  14.         }
  15.        
  16.         return redirect()->back();
  17.     }
  18.  
  19. @extends('layouts.users.index')
  20.  
  21. @section('content')
  22. <!-- Title Page -->
  23. @if ($message = Session::get('success'))
  24. <div class="alert alert-success alert-block">
  25.     <button type="button" class="close" data-dismiss="alert">×</button>
  26.     <strong>{{ $message }}</strong>
  27. </div>
  28. @endif
  29.  
  30. <section class="bg-title-page p-t-40 p-b-50 flex-col-c-m" style="background-image: url({{ asset('assets_front/images/food.jpg')}} );">
  31.     <h2 class="l-text2 t-center">
  32.         Cart
  33.     </h2>
  34. </section>
  35.  
  36. <!-- Cart -->
  37. <section class="cart bgwhite p-t-70 p-b-100">
  38.     <div class="container">
  39.         <form id="" action="/update-cart" method="post" enctype="multipart/form-data">
  40.             {{ csrf_field() }}
  41.             <!-- Cart item -->
  42.             <div class="container-table-cart pos-relative">
  43.                 <div class="wrap-table-shopping-cart bgwhite">
  44.                     <table class="table-shopping-cart">
  45.                         <tr class="table-head" style="background-color: #f59000;">
  46.                             <th class="column-1"></th>
  47.                             <th class="column-2">Product</th>
  48.                             <th class="column-3">Price</th>
  49.                             <th class="column-4">Quantity</th>
  50.                             <th class="column-5">Total</th>
  51.                         </tr>
  52.  
  53.                         @foreach($cart_header as $d)
  54.                         @if($d->publication_status_cart == 0)
  55.                         <?php
  56.                         $customer_id = Auth::user()->id;
  57.                         ?>
  58.                         @if($d->customer_id == $customer_id)
  59.                         <input type="hidden" id="" name="cart_id[]" value="{{ $d->cart_id }}" required="required" class="form-control col-md-7 col-xs-12">
  60.                         <input type="hidden" id="" name="price_product" value="{{ $d->price_product }}" required="required" class="form-control col-md-7 col-xs-12">
  61.                         <tr class="table-row">
  62.                             <td class="column-1">
  63.                                 <div class="cart-img-product b-rad-4 o-f-hidden">
  64.                                     <img src="{{ asset('assets/image_products/'.$d->image_product) }}" alt="IMG-PRODUCT">
  65.                                 </div>
  66.                             </td>
  67.                             <td class="column-2">{{ $d->name_product}}</td>
  68.                             <td class="column-3">Rp.{{number_format($d->price_product,0)}}</td>
  69.                             <td class="column-4">
  70.                                 <div class="flex-w bo5 of-hidden w-size17">
  71.                                     <button type="submit" class="btn-num-product-down color1 flex-c-m size7 bg8 eff2">
  72.                                         <i class="fs-12 fa fa-minus" aria-hidden="true"></i>
  73.                                     </button>
  74.                                     <input class="size8 m-text18 t-center num-product" type="number" name="qty_cart[]" value="{{ $d->qty_cart }}">
  75.  
  76.                                     <button type="submit" class="btn-num-product-up color1 flex-c-m size7 bg8 eff2">
  77.                                         <i class="fs-12 fa fa-plus" aria-hidden="true"></i>
  78.                                     </button>
  79.                                 </div>
  80.                             </td>
  81.                             <td class="column-5">Rp.{{number_format($d->price_cart,0)}}</td>
  82.                         </tr>
  83.                         @endif
  84.                         @endif
  85.                         @endforeach
  86.                     </table>
  87.                 </div>
  88.             </div>
  89.  
  90.             <div class="flex-w flex-sb-m p-t-25 p-b-25 bo8 p-l-35 p-r-60 p-lr-15-sm">
  91.                 <div class="flex-w flex-m w-full-sm">
  92.                    
  93.                 </div>
  94.  
  95.                 <div class="size10 trans-0-4 m-t-10 m-b-10">
  96.                     <!-- Button -->
  97.                     <button class="flex-c-m sizefull bg1 bo-rad-23 hov1 s-text1 trans-0-4">
  98.                         Update Cart
  99.                     </button>
  100.                 </div>
  101.             </div>
  102.         </form>
  103.  
  104.         <!-- Total -->
  105.     </div>
  106. </section>
  107. @endsection
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement