Crinsane / LaravelShoppingcart

A simple shopping cart implementation for Laravel
MIT License
3.68k stars 1.73k forks source link

How To remove single product from the cart #617

Open gagsy opened 4 years ago

RodrigoPauletti commented 4 years ago

It's very easy. You only need use the method remove($rowId) passing the product's rowId as a parameter:

Cart::remove('productRowId');

To get the product's rowId, you can use Cart::search() and compare any property from $cartItem:

$rowId = $cart->search(function ($cartItem, $rowId) {
    return $cartItem->id === 1;
});
// The return will be the product's rowId