Laravel 5.2 multi auth example using Auth guard from scratch

Multiple authentication is very important in big application of laravel. If you work on large project then you mostly prefer to diferente tables, like you always prefer "users" table for site user registration and "admins" table for admin user that way make strong security. we always use Auth for making user authentication but you have question how to make admins with auth then you can do easily by following step.

Step 1: Auth Config Setting

In this step we will add new admin guard from auth.php file of config directory. so first open auth.php file and add bellow code.

config/auth.php

return [

'defaults' => [

'guard' => 'web',

'passwords' => 'users',

],

'guards' => [

'web' => [

'driver' => 'session',

'provider' => 'users',

],

'api' => [

'driver' => 'token',

'provider' => 'users',

],

'admin' => [

'driver' => 'session',

'provider' => 'admins',

],

],

'providers' => [

'users' => [

'driver' => 'eloquent',

'model' => App\User::class,

],

'admins' => [

'driver' => 'eloquent',

'model' => App\Admin::class,

]

],

'passwords' => [

'users' => [

'provider' => 'users',

'email' => 'auth.emails.password',

'table' => 'password_resets',

'expire' => 60,

],

'admins' => [

'provider' => 'admins',

'email' => 'auth.emails.password',

'table' => 'password_resets',

'expire' => 60,

],

],

];

Step 2: Create Models

In this step we have to create two model for User and Admin. I think we have already User.php model will available but make sure just compare code is the same or not. so fist check bellow User.php model.