Advertisement
Guest User

Untitled

a guest
Apr 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. <input type="number" onchange="changeQuantity(this.value, '{{$cartProduct->id}}')" id="quantity" class="form-control text-center" value="{{$cartProduct->quantity}}">
  2.  
  3.  
  4.  <script>
  5.         $.ajaxSetup({
  6.             headers: {
  7.                 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  8.             }
  9.         });
  10.  
  11.         function changeQuantity(quantity, productId) {
  12.             $.ajax
  13.             ({
  14.                 type: "post",
  15.                 url: '{{ route('cart.updateproduct') }}',
  16.                 data: { quantity: quantity, productId: productId }
  17.             })
  18.         };
  19.     </script>
  20.  
  21. Route::post('/shoppingcart/updateproduct',  'ShoppingCartController@updateProduct')->name('cart.updateproduct');   
  22.  
  23.     /***
  24.      * Update existing product quantity
  25.      * @param Request $request
  26.      */
  27.     public function updateProduct(request $request){
  28.  
  29.         $user = Auth::user();
  30.  
  31.         if(is_numeric($request->quantity))
  32.         {
  33.             DB::table('cart_product')->where([
  34.                 ['productId', $request['productId']],
  35.                 ['cartId', $user->cartId]
  36.             ])->update(array('quantity' => $request['quantity']));
  37.         }
  38.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement