dsh7551 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) {
        dd(session('cart'));
        // 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?

  • 写回答

1条回答 默认 最新

  • 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?