duangao8359 2017-01-19 07:34
浏览 135

Laravel Auth ::后卫(后卫) - > check()没有按预期工作

I am making a homework web app using Laravel and I am trying to add 3 different groups of people: admins, teachers and students. I have created all of these as models and they all have tables in the database. The login script works and logs the user in however the problem occurs when I use this code

    if(Auth::guard('student')->check() || Auth::guard('teacher')->check() || Auth::guard('admin')->check()) {
        return Redirect::to('/admin/overview')->send();
    }

The login works because when I enter a correct username and password I get redirected away but when I use an incorrect username and password I get redirected to the same page.

My problem is that line of code doesn't do anything it seems that Auth::guard('student')->check() always returns false. Which is weird because this:

    if(Auth::guard('student')->attempt($credentials)) {
        return Redirect::to('/student/overview')->send();
    }

returns true and redirects me to /student/overview

  • 写回答

1条回答 默认 最新

  • douan6815 2017-01-19 08:53
    关注

    I faced the same issue then I tried first create the instance of Auth and then use check()

    You need to manage this way just try this hope it helps you

    $auth = Auth::guard('student');
    if ($auth->check()) {
        return Redirect::to('/admin/overview')->send();
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因