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

MrRobot21's avatar

Laravel Vue Shopping Cart

Hi Awesome People

I'm working on a e-commerce project, i'm building the api in Laravel for Mobile Apps and for the web app, i'm using vue-cli for web app

since the api is stateless which uses passport to authenticate user, i couldn't figure out the best way to create the cart functionality with the session and all

1 -> should i create a cart table in database and CRUD the cart details from front end Vue app and the mobile app

2 -> is there a way to create stateless shopping cart

i'm desperate to know how to do it

thank you

0 likes
5 replies
Codeskills's avatar

I wound personally create a cart table with expiration date and device/user identification.

So it expires automatically after some time, and the user can see the cart on all of its devices, and unauthorized can see it on the device.

1 like
MrRobot21's avatar

@Codeskills thank you so much for your time

i got i part about storing the cart items in cart table when user is authorized/logged in with the user id

but when user is not logged in or in case of guest user, should i be storing the cart details in the Vue js side in a localstorage or something

thank you

Codeskills's avatar

I would store it in the session. You should be able to create a session for not logged in users and then store it in the cart table to identify the guest user.

1 like
MrRobot21's avatar

@Codeskills the laravel api and the vue.js 2 runs in different domains. the vue app runs by making http request to laravel api

in this case how do i maintain a session at laravel end or should i use the sessionStore of browser at vue app

thank you

Codeskills's avatar
Level 7

Well then, I would store it in the cookies.

Let's say you start shopping

  1. you add an item to the cart (if it does not exists you create a cart)
  2. vue -> you send it to the api (the item and cookies card_id if exists)
  3. [api] if the cart_id is provided you look it up and add the item, if not you create new cart and add the item, both returning the cart_id and possible the list of all item ids in the cart.

Hope it helps.

1 like

Please or to participate in this conversation.