1
votes

I used the authentication system built in Laravel 6. I can't seem to redirect the users based on their roles.

These are my columns in users table:

  • username
  • password
  • email
  • roleid

In my LoginController, I added this code:

public function redirectTo(){

    // User role
    $role = Auth::user()->roleid; 

    // Check user role
    switch ($role) {
        case 1:
                return '/';
            break;
        case 2:
                return '/application/candidates';
            break; 
    }
}

When I tried to login using different credentials with different roles, I always end up on the root route.

Am I missing something?

1
Are you sure your code is getting to this point and that you aren't being redirected earlier on, e.g. by middleware?D Malan
Hi, yup. When I tried to place dd inside redirectTo() method, I was able to get the value of roleid. But when I revert back to the original code, it always redirect to root route after logging in.Lou KnowsAlready

1 Answers

0
votes

Have you tried:

return redirect('/');

instead of

return '/';