Laravel: 登录后空白页面,然后检查角色
Laravel: blank page after login and then checking for roles
我正在使用 Laravel 的本机身份验证模块进行登录并使用 entrust 进行用户角色。
当用户登录时,laravel 的本地身份验证模块仅检查 username/email 和密码。然后让用户登录。我检查用户是否使用某个 user_type 登录(user_type 也已发布)并且用户具有该角色,然后将用户发送到该角色的仪表板,否则用户被 Auth::logout 注销并重定向到错误 user_type 错误的登录页面。
除 user_type 错误外,所有代码均有效,然后显示空白登录页面。我已经尝试了很多重定向组合,但没有成功。
我的注销和重定向代码是
protected function logoutRedirect(Request $request)
{
Auth::logout();
return redirect($this->loginPath())
->withInput($request->only($this->loginUsername(), 'remember'))
->withErrors([
$this->loginRole() => $this->getWrongRoleMessage(),
]);
/*
return view('auth.login')
->withInput($request->only($this->loginUsername(), 'remember'))
->withErrors($this->getWrongRoleMessage());
*/
/*
return redirect('/auth/login')->withErrors([$this->loginRole() => $this->getWrongRoleMessage()]);
*/
}
我已经将我可以尝试的所有重定向方法以注释的形式放在上面的代码中。如果您能找到错误或者您能提出更好的解决方案,请告诉我。我是 laravel 的新手,所以如果你能帮助我解决这个初学者问题,我将不胜感激。
PS:顺便说一句,我在本地主机上使用 Laravel 5.1 (xampp + MS windows 7)
最后我通过搜索其他东西的解决方案无意中找到了解决方案。令人惊讶的是,这在任何论坛的任何地方都没有提及。
这是让我返回错误的代码。
redirect()->back()->withErrors([$this->loginRole() => $this->getWrongRoleMessage()]);
我正在使用 Laravel 的本机身份验证模块进行登录并使用 entrust 进行用户角色。
当用户登录时,laravel 的本地身份验证模块仅检查 username/email 和密码。然后让用户登录。我检查用户是否使用某个 user_type 登录(user_type 也已发布)并且用户具有该角色,然后将用户发送到该角色的仪表板,否则用户被 Auth::logout 注销并重定向到错误 user_type 错误的登录页面。
除 user_type 错误外,所有代码均有效,然后显示空白登录页面。我已经尝试了很多重定向组合,但没有成功。
我的注销和重定向代码是
protected function logoutRedirect(Request $request)
{
Auth::logout();
return redirect($this->loginPath())
->withInput($request->only($this->loginUsername(), 'remember'))
->withErrors([
$this->loginRole() => $this->getWrongRoleMessage(),
]);
/*
return view('auth.login')
->withInput($request->only($this->loginUsername(), 'remember'))
->withErrors($this->getWrongRoleMessage());
*/
/*
return redirect('/auth/login')->withErrors([$this->loginRole() => $this->getWrongRoleMessage()]);
*/
}
我已经将我可以尝试的所有重定向方法以注释的形式放在上面的代码中。如果您能找到错误或者您能提出更好的解决方案,请告诉我。我是 laravel 的新手,所以如果你能帮助我解决这个初学者问题,我将不胜感激。
PS:顺便说一句,我在本地主机上使用 Laravel 5.1 (xampp + MS windows 7)
最后我通过搜索其他东西的解决方案无意中找到了解决方案。令人惊讶的是,这在任何论坛的任何地方都没有提及。
这是让我返回错误的代码。
redirect()->back()->withErrors([$this->loginRole() => $this->getWrongRoleMessage()]);