Laravel 5.3 LoginController - Header can contain at most one header, newline detected
I have a problem when changing the default redirect LoginController
after login, I get
ErrorException in Response.php line 339:
Header may not contain more than a single header, new line detected
I already tried everything but it just doesn't work, code:
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 the Laravel documentation, this method takes precedence over the attribute, so I assume it left the class attribute as it is.
And also, I already checked and the code does reach the last condition.
0
source to share
3 answers
I just decided to replace the original code,
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo;
protected function redirectTo()
{
if(\Auth::user()->hasRole('copy')){
$this->redirectTo = '/copy/dashboardCopy';
return $this->redirectTo;
}
}
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
}
}
0
source to share