duan32342 2019-02-03 20:41
浏览 72
已采纳

注册后的Laravel 5.1 Auth ::尝试无法访问另一页面上的用户数据

I am having an issue with accessing the authenticated user data once registered on the system.

After carrying out some validation within my Registration process I have this line:

if (Auth::attempt(array(
        'username' => $customer->username,
        'password' => $data['password']
    ))) {
        return redirect('profile-setup');
    }

I have tried die to see the user data within this if statement, like this:

dd(Auth::user());

This actually works and I can see the user data.

However When I go to the blade profile-setup, I tried the same die but I am getting a null value.

I am not sure as to what I have missed out.

If there's anything that needs to be provided from my end please just let me know. Any help with be appreciated.

Thanks

  • 写回答

1条回答 默认 最新

  • douwen1929 2019-02-03 22:07
    关注

    You can see if any of this is present in your case :

    • Specifying protected $primaryKey = 'user__table_id_column_name'; in user model
    • If you see the method signature inside the larvel's core you will see :

    public function attempt(array $credentials = [], $remember = false, $login = true){ .. }

    So try passing second argument to attempt as true and see if it persists. This should not be the case as this should happen automatically but try once for safe fide

    • Remove echo statements if you have any for debugging
    • Check if you are calling Auth::logout() anywhere by mistake before the last dd
    • try redirect()->intended('profile-setup');

    For more help follow just check thread : Laravel Auth:attempt() will not persist login

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

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题