I've been trying forever to figure out how to create separate login views for different types of users in Laravel. I have one User model and then a roles table and role_users table. I do need to have users pick how they would like to login (i.e. as an Advisor, HR Admin, Employee). For example, one user can have both the Employee and HR Admin Role.
Here is what I attempted, using Laravel 7:
- Install the Auth scaffolding
- Create view called advisor-login by copying the login view that comes with basic Laravel Auth
- Create AdvisorLoginController by copying the LoginController that comes with basic Laravel Auth
- Create advisor-login route that directs to the AdvisorLoginController. Update the action in the advisor-login view to go to this route
In the AdvisorLoginController, we have:
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
The "protected $redirectTo = RouteServiceProvider::HOME;" part is relatively straightforward as I could modify this to go to the Advisor Dashboard after logged in.
But the AuthenticatedUsers trait presents a problem. I went down this rabbit hole and couldn't get out. I tried to copy the AuthenticateUsers files from with the Laravel/UI package and create an AuthenticateAdvisors trait, but this became a mess.
Am I missing an easy fix here?