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
Comment This Part in Authenticate.php Of app/Http/Middleware
protected function redirectTo($request)
{
if (! $request->expectsJson()) {
return view('admin.auth.login');
}
}
The method redirectTo should return an url path, not the Redirect response.
...
protected function redirectTo()
{
if(\Auth::user()->hasRole('copy')){
return '/copy/dashboardCopy';
}
}
...
public $redirectTo = '/lender/home';
protected function redirectTo()
{
if(\Auth::guard('lender')->check()){
$this->redirectTo = '/lender/home';
return $this->redirectTo;
}
}
I have just solved it replacing the original code, with
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']);
}
}