I am trying to redirect a user after login. I want a user employee to be redirected to /home and user admin to /admin. Only one user is redirected and the other is showing 401
Unauthorized and the url is still /login.
public function redirectTo(){
if (Auth::user()->authorizeRoles('employee') == true) {
return '/home';
}else if (Auth::user()->authorizeRoles('admin') == true) {
return view('admin');
}else {
return 'login';
}
Return your routes wrapped in the redirect() method.
And since you're returning early, you can clean the code up by removing the unnecessary else statements.
public function redirectTo()
{
if (Auth::user()->authorizeRoles('employee') == true) {
return redirect('/home');
}
if (Auth::user()->authorizeRoles('admin') == true) {
return view('admin');
}
return redirect('/login');
}
@JAURENIGEL - Which routes are not working? Notice that you are returning a view() for your 'admin' and a redirect() for your employees. Is that intentional?