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.

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

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看