8 months ago

Updating Cart Quantity with Crinsane/LaravelShoppingcart

Posted 8 months ago by greevesh

I'm trying to update the quantity of items in my cart with this package:

Has anyone used this before?

If so, my question is, is there an easy way to increase the quantity of items in your cart? I've read the documentation for this package but there doesn't seem to be much there to help with this problem.

So far, I've only managed to update the quantity to 2 after pressing a button. What if if I want to have multiple options for increasing the quantity? So the user has the option of choosing 1, 2, 3, 4 products and so on.

// CartController.php

public function update(Request $request, $rowId)
        Cart::update($rowId, 2);
        return back()->with('quantityIncreasedMessage', 'Product quantity has been increased.');

As you can see above, the first parameter of the update method is the product id and the second parameter is the quantity.

This doesn't work:

Cart::update($rowId, ++)
// cart.blade.php

<td class="border-0 align-middle">
   <form action="{{ route('cart.update', $product->rowId) }}" method="POST">
  {{ method_field('PATCH') }}
// web.php

Route::patch('/cart/{rowId}', '[email protected]')->name('cart.update');

Please sign in or create an account to participate in this conversation.