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

liandhas's avatar

How to manage cart in Laravel API?

I have used sessions and cookies to manage cart in laravel application. In laravel API, do I need to use session, cookies for add to cart? or is there any way?

0 likes
3 replies
automica's avatar
automica
Best Answer
Level 54

depends on how you are interacting with your API.

if you want your cart to be remembered, then you should be saving it in a DB along with an identifier for the client, especially if you have logged.

API should be stateless and not have to be relied on to remember sessions or cookies.

I don't know anything about your application so a little insight into that might make your question easier to answer.

martinbean's avatar

@lianmaymesi Well APIs are usually stateless so no, you won’t be able to use sessions nor cookies. Instead, you’ll need to generate a unique identifier for carts that the client then uses to interact with that cart (add/remove items, check out, etc).

Please or to participate in this conversation.