LoginController
登录后更改默认重定向时出现问题,ErrorException in Response.php line 339: Header may not contain more than a single header, new line detected
我已经尝试了所有方法,但是它不起作用,代码是:
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属性保持原样。
而且,我已经检查过了,代码实际上达到了最后一个条件。
方法redirectTo应该返回一个URL路径,而不是Redirect响应。
...
protected function redirectTo()
{
if(\Auth::user()->hasRole('copy')){
return '/copy/dashboardCopy';
}
}
...
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句