Hi!
I am building a small custom shopping cart with some specific needs.
Whenever a product is added to the cart I am trying to save that products category to the session.
I have a route that a hit via Axios in my vue file that has a simple method on the controller that is suppose to save the session.
$request->session()->put($request->service, true);
But nothing is saving.
I also have another method on that controller that removes a key from the session if a product is removed from the cart. Same idea.
$request->session()->forget($request->service);
I have my config set to file and getting zero errors. Just when i return all() those items are not in the session. Could it have to do with calling via Axios? Maybe something is needed in the header?
Thank You
Since you mention axois, I'm guessing you're building a single page app (or at least some page where you do more than one ajax call to the server); I highly recommend NOT to use sessions for it. Sessions are saved by Laravel at the end of the request, meaning that when you have two simultaneous requests, you might loose information that you added.
For building single page apps, you need to think about calling your REST API from within your javascript, and make your code stateless.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community