8 months ago

Redirect to same page with cookie

Posted 8 months ago by timgavin
  1. I have a shopping cart page located at /cart, which shows the user their cart contents.
  2. The cart contents are stored in a cookie.
  3. The Route is set up as Resource::get('/cart', '[email protected]');
  4. A user can add items to their cart if they are not logged in, but in order to make a purchase they have to login.

Now, in [email protected] I check if the user is logged in, and if so check their purchase history to see if they've ordered this item before. If they have, I remove the item from the cart cookie.

My problem is that when returning from the index method, I have to use return view('cart.index') because if I use return redirect('/cart') I'm stuck in an infinite loop.

However, if I don't use redirect the cookie doesn't update.

How can I update the cookie and send them to the /cart page?

Please sign in or create an account to participate in this conversation.