2017-07-20 09:09
浏览 52

在Laravel 5.4中登录时会删除会话项

When a guest user puts items into a cart, they are stored in a session like session('cart', 'item1'). However once user has logged in, this session gets destroyed for some reason, and I can no longer access it. Why does this session is removed and how do I keep it after user log in?

I tried to dd() the session even before the validation and login attempt takes place, but it still is removed.

public function postLogin(Request $request) {
        // validate
        // attempt to log in

It seems that it gets removed after "post". Is it a normal behavior in Laravel 5 or I'm doing something wrong?

图片转代码服务由CSDN问答提供 功能建议

当访客用户将商品放入购物车时,他们会存储在 session('cart)等会话中 ','item1')。 但是,一旦用户登录,该会话由于某种原因被破坏,我无法再访问它。 为什么会话被删除以及如何在用户登录后保留它?

我甚至在验证和登录尝试发生之前尝试了dd()会话,但它仍然是 删除。

  public function postLogin(Request $ request){
 // validate / n //尝试登录 

似乎在“post”之后删除了它。 这是Laravel 5中的正常行为还是我做错了什么?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongmu1989
    dongmu1989 2017-07-20 09:36

    Got the solution.

    To store the guest user data use the php session like $_SESSION['cart']='item1' not Laravel one because Laravel stores its session data in the different file and it flush data of its own.

    点赞 评论