Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Demers94's avatar

Removing items from session cart array

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.

0 likes
1 reply
d3xt3r's avatar
d3xt3r
Best Answer
Level 29

Read the cart, remove the item and push it back.

1 like

Please or to participate in this conversation.