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']);
}
}
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.
The method redirectTo should return an url path, not the Redirect response.
...
protected function redirectTo()
{
if(\Auth::user()->hasRole('copy')){
return '/copy/dashboardCopy';
}
}
...