简体   繁体   English

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

[英]Session item is getting removed on login in Laravel 5.4

When a guest user puts items into a cart, they are stored in a session like session('cart', 'item1') . 当来宾用户将商品放入购物session('cart', 'item1') ,它们会存储在会话中,例如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. 我什至在进行验证和登录尝试之前尝试dd()会话,但仍将其删除。

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? 这是Laravel 5中的正常行为,还是我做错了什么?

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. 要存储来宾用户数据,请使用$_SESSION['cart']='item1'类的php会话,而不要使用Laravel,因为Laravel将其会话数据存储在不同的文件中,并刷新自己的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM