【问题标题】:how to redirect in laravel 5 after authenticating particular user验证特定用户后如何在 laravel 5 中重定向
【发布时间】:2016-05-11 00:26:03
【问题描述】:

我是 Laravel 新手,我正在尝试根据存储在数据库中的 ID 在不同页面上重定向 2 种不同类型的用户。

我在redirectifAuthenticated.php 文件中找到了验证重定向代码。我不知道我在代码中做错了什么才能成功重定向。下面是我的代码。

public function handle($request, Closure $next){
     if ($this->auth->check()){
          $userId = Auth::id();
          if($userId == '1'){
             return new RedirectResponse(url('/symptoms/view'));
          }else{
             return new RedirectResponse(url('/home'));
          }
     }
     return $next($request);
}

【问题讨论】:

  • 在您的帖子中添加中间件代码
  • 哪个中间件代码? authenticate.php 还是 verifycsrftoken?
  • 只需执行“return redirect(url('/symptoms/view'));”无需使用 RedirectResponse 类...
  • 查看我对此的回答:stackoverflow.com/q/34880747/2668477

标签: php authentication redirect laravel-5


【解决方案1】:

从你的代码我可以看到一个重定向循环,如果你把你的重定向放在那里逻辑不正确,你应该把重定向放在你的函数中
user 是 login,就像 LoginController 中的一个名为 signin 的函数。

还有一个重定向return redirect()->url('xxx')的捷径

【讨论】:

    猜你喜欢
    • 2016-07-25
    • 2017-08-17
    • 2011-11-08
    • 1970-01-01
    • 2020-11-02
    • 2020-06-09
    • 1970-01-01
    • 1970-01-01
    • 2017-04-09
    相关资源
    最近更新 更多