The best way I've found is to use Traits . What we will do is basically the same, but less complex and structured:
1. Instead of creating two tables, our user model will have a role field, in my case I will have: "admin", "employee" and "user".
2. We are going to create a folder with traits, in which case it will be placed in App/Http .
3. We are going to create a new file and call it RedirectTrait.php inside this folder with this content:
<?php namespace App\Http\Traits;
As you can see, we can โplayโ with redirects, but the intended one is necessary. According to laravel documentation:
The designated redirect method redirects the user to the URL they were trying to access before being intercepted by the middleware authentication. A fault-tolerant URI can be provided to this method if the intended destination is not available.
4. Finally, we place the attribute and name it:
- In the file
App/Http/Controllers/Auth/LoginController.php
use Illuminate\Http\Request;
We are rewriting the 'authenticated' method placed in Illuminate\Foundation\Auth\AuthenticatesUsers (which is empty, by the way)
- We will do the same in the file
App/Http/Controllers/Auth/RegisterController.php , but the method will have a different name:
protected function registered(Request $request, $user) { return $this->RedirectBasedInRole($request, $user); }
We are rewriting the redirection method stored in Illuminate\Foundation\Auth\RegistersUsers and is also empty.
5. Enjoy: D
PS. Password forwarding reset is another story.