Level 29
Read the cart, remove the item and push it back.
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm using sessions to store the list of Formation items that the user has in his cart.
Here's how an item is added to the cart:
session()->push('cart', $request->formation_id);
I want to add the ability to remove items from the cart. I see this in the documentation :
session()->forget('key');
... but I don't see how to use this when the value is an array. How can I remove an item from the session cart? The controller method receives the formation_id as a parameter, like the add() method does.
Read the cart, remove the item and push it back.
Please or to participate in this conversation.