This is a simple method of implementing multi-model / guard authentication into laravel using the default laravel authentication structure. (NOTE: passport // API integration not included yet)
php composer make:auth
cp App/User.php App/Admin.php
- Edit
App/Admin.php
and change the class name to Admin - Edit
config/auth.php
and add the following
...
'guards' => [
...
'admin' => [
'driver' => 'session',
'provider' => 'admin',
],
'admin_api' => [
'driver' => 'passport',
'provider' => 'admin',
'hash' => false,
],
],
...
'providers' => [
...
'admin' => [
'driver' => 'eloquent',
'model' => App\Admin::class,
],
],
...
'passwords' => [
...
'admin' => [
'provider' => 'admin',
'table' => 'password_resets',
'expire' => 60,
],
],
php make:middleware AuthGuard
- Edit
app/Http/Middleware/AuthGuard.php
to contain the following file. - Edit
app\Http\Kernel.php
...
protected $middlewareGroups = [
'web' => [
...
\App\Http\Middleware\AuthGuard::class,
],
...