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

AydenWH's avatar

Storing Array Into HTTP Session

I am using HTTP Session to store the cart item for the user who never log in into the system which is guest.

I want to store those cart items into the HTTP Session as a array. How do I achieve this?

"cart_item" => array:1 [
    "box" => array:2 [
        "quantity" => 1,
        "price" => 49.90
    ]
]
0 likes
2 replies
Jaytee's avatar
Jaytee
Best Answer
Level 39
session([
    'cart_item' => [
        'box' => [
            'quantity' => 1,
            'price' => 49.90
        ]
    ]
]);

to get it from the session:

session('cart_item'); // i'm pretty sure this retrieves
session()->get('cart_item');

Please or to participate in this conversation.