I have recently started learning Laravel. I am overriding the redirectTo() method in the default LoginController in my Laravel app.
class LoginController extends Controller
{
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
protected function redirectTo()
{
return '/dashboard';
}
}
It is working fine but if an already authenticated user tries to login again (the user has not logged out and tries to visit the '/login' route), the user is redirected to '/home' which obviously is the RouteServiceProvider::HOME constant. I can simply change the RouteServiceProvider::HOME constant but there must surely be a better option. Also, if the redirect depends on the role of the user then simply changing the constant won't do any good. So what is the proper way of overriding the RouteServiceProvider::HOME constant?