Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <input type="number" onchange="changeQuantity(this.value, '{{$cartProduct->id}}')" id="quantity" class="form-control text-center" value="{{$cartProduct->quantity}}">
- <script>
- $.ajaxSetup({
- headers: {
- 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
- }
- });
- function changeQuantity(quantity, productId) {
- $.ajax
- ({
- type: "post",
- url: '{{ route('cart.updateproduct') }}',
- data: { quantity: quantity, productId: productId }
- })
- };
- </script>
- Route::post('/shoppingcart/updateproduct', 'ShoppingCartController@updateProduct')->name('cart.updateproduct');
- /***
- * Update existing product quantity
- * @param Request $request
- */
- public function updateProduct(request $request){
- $user = Auth::user();
- if(is_numeric($request->quantity))
- {
- DB::table('cart_product')->where([
- ['productId', $request['productId']],
- ['cartId', $user->cartId]
- ])->update(array('quantity' => $request['quantity']));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement