greevesh
1 week ago
103
2
Laravel

Updating Cart Quantity with Crinsane/LaravelShoppingcart

Posted 1 week ago by greevesh

I'm trying to update the quantity of items in my cart with this package: https://github.com/Crinsane/LaravelShoppingcart

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">
     @csrf
  {{ method_field('PATCH') }}
  <button>+</button>
  </form>
</td>
// web.php

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

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