title: Multi Auth with single user table in laravel 5.2
body: <p>I want to Multi Auth with <code>single</code> table in laravel 5.2.</p>
  
  <p>I tried this way. But frontend login working.</p>
  
  <p>Laravel 5.2 has a new <code>artisan</code> command.  </p>
  
  <p><code>php artisan make:auth</code>  </p>
  
  <p>it will generate basic login/register <code>route</code>, <code>view</code> and <code>controller</code> for <code>user</code> table.  </p>
  
  <p>Make a <code>admin</code> table as <code>users</code> table for simplicity.  </p>
  
  <p><strong>Controller For Admin</strong><br>
  <code>app/Http/Controllers/AdminAuth/AuthController</code><br>
  <code>app/Http/Controllers/AdminAuth/PasswordController</code><br>
  (note: I just copied these files from <code>app/Http/Controllers/Auth/AuthController</code> here)  </p>
  
  <p><strong><code>config/auth.php</code></strong>  </p>
  
  <pre><code>//Authenticating guards
  
  return [
  'guards' =&gt; [
      'user' =&gt;[
      'driver' =&gt; 'session',
      'provider' =&gt; 'user',
      ],
      'admin' =&gt; [
      'driver' =&gt; 'session',
      'provider' =&gt; 'admin',
      ],
  ],  
  
  //User Providers
  'providers' =&gt; [
      'user' =&gt; [
      'driver' =&gt; 'database',
      'table' =&gt; 'user',
      'model' =&gt; App\User::class,
      ],
      'admin' =&gt; [
      'driver' =&gt; 'database',
      'table' =&gt; 'user',
      'model' =&gt; App\Admin::class,
      ]
  ],  
  
  //Resetting Password  
  'passwords' =&gt; [
      'clients' =&gt; [
      'provider' =&gt; 'client',
      'email' =&gt; 'auth.emails.password',
      'table' =&gt; 'password_resets',
      'expire' =&gt; 60,
      ],
      'admins' =&gt; [
      'provider' =&gt; 'admin',
      'email' =&gt; 'auth.emails.password',
      'table' =&gt; 'password_resets',
      'expire' =&gt; 60,
      ],
  ],
  ]; 
  </code></pre>
  
  <p><strong><code>route.php</code></strong>  </p>
  
  <pre><code>Route::group(['middleware' =&gt; ['web']], function () {
      //Login Routes...
      Route::get('/admin/login','AdminAuth\AuthController@showLoginForm');
      Route::post('/admin/login','AdminAuth\AuthController@login');
      Route::get('/admin/logout','AdminAuth\AuthController@logout');
  
      // Registration Routes...
      Route::get('admin/register', 'AdminAuth\AuthController@showRegistrationForm');
      Route::post('admin/register', 'AdminAuth\AuthController@register');
  
      Route::get('/admin', 'AdminController@index');
  
  });  
  </code></pre>
  
  <p><strong><code>AdminAuth/AuthController.php</code></strong>  </p>
  
  <p>Add two methods and specify <code>$redirectTo</code> and <code>$guard</code>  </p>
  
  <pre><code>protected $redirectTo = '/admin';
  protected $guard = 'admin';
  public function showLoginForm()
  {
      if (view()-&gt;exists('auth.authenticate')) {
          return view('auth.authenticate');
      }
  
      return view('admin.auth.login');
  }
  public function showRegistrationForm()
  {
      return view('admin.auth.register');
  }  
  </code></pre>
  
  <p>it will help you to open another login form for admin  </p>
  
  <p><strong>creating a middleware for <code>admin</code></strong>  </p>
  
  <pre><code>class RedirectIfNotAdmin
  {
  /**
   * Handle an incoming request.
   *
   * @param  \Illuminate\Http\Request  $request
   * @param  \Closure  $next
   * @param  string|null  $guard
   * @return mixed
   */
  public function handle($request, Closure $next, $guard = 'admin')
  {
      if (!Auth::guard($guard)-&gt;check()) {
          return redirect('/');
      }
  
      return $next($request);
  }
  </code></pre>
  
  <p>}  </p>
  
  <p>register middleware in <code>kernel.php</code>  </p>
  
  <pre><code> protected $routeMiddleware = [
      'admin' =&gt; \App\Http\Middleware\RedirectIfNotAdmin::class,
  ];
  </code></pre>
  
  <p>use this middleware in <code>AdminController</code> 
  e.g.,<br>
  
  
  <pre><code>namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  
  use App\Http\Requests;
  use App\Http\Controllers\Controller;
  use Illuminate\Support\Facades\Auth;
  
  class AdminController extends Controller
  {
      public function __construct(){
          $this-&gt;middleware('admin');
     }
  public function index(){
          return view('admin.dashboard');
      }
  }
  </code></pre>