Laravel 5.3 LoginController-标头不能包含多个标头,检测到新行 [英] Laravel 5.3 LoginController - Header may not contain more than a single header, new line detected
问题描述
我在登录后更改默认的LoginController
重定向时遇到问题,
ErrorException in Response.php line 339:
Header may not contain more than a single header, new line detected
I have a problem when changing the default LoginController
redirect after login, I'm getting an
ErrorException in Response.php line 339:
Header may not contain more than a single header, new line detected
我已经尝试了所有方法,但无法正常工作,代码为:
I have already tried everything but it just does not work, the code is:
class LoginController extends Controller
{
protected $redirectTo = '/home';
protected function redirectTo()
{
if (\Auth::check()) {
$user_id = \Auth::id();
$usuario = users::where('id','=',$user_id)->first();
if($usuario->hasRole('copy')){
return redirect('/copy/dashboardCopy');
}
}
}
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
}
}
根据Laravel文档,该方法具有比属性更高的优先级,因此我认为可以将class属性保持原样.
According to Laravel documentation, the method has higher priority than the attribute, so I assume it's okay to leave the class attribute as it is.
而且,我已经检查过了,代码实际上已经达到了最后一个条件.
And also, I have already checked, and the code is actually reaching the last condition.
推荐答案
redirectTo方法应返回url路径,而不是Redirect响应.
The method redirectTo should return an url path, not the Redirect response.
...
protected function redirectTo()
{
if(\Auth::user()->hasRole('copy')){
return '/copy/dashboardCopy';
}
}
...
这篇关于Laravel 5.3 LoginController-标头不能包含多个标头,检测到新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!