title: Laravel 5: how should I implement Auth::admin() as Auth::guest()?
body: <p>I would like to have administrator authorization. so I have new class in middleware</p>
  
  <pre><code>class Admin {
  
  public function handle($request, Closure $next)
  {
  
      if ( Auth::check() &amp;&amp; Auth::user()-&gt;isAdmin() )
      {
          return $next($request);
      }
  
      Session::flash('message', 'You need to be an administrator to visit this page.');
  
      return redirect('/');
  
  }
  
  }
  </code></pre>
  
  <p>Then register it in Kernel.php by adding</p>
  
  <pre><code>protected $routeMiddleware = [
      'auth' =&gt; \App\Http\Middleware\Authenticate::class,
      'auth.basic' =&gt; \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
      'guest' =&gt; \App\Http\Middleware\RedirectIfAuthenticated::class,
      'admin' =&gt; \App\Http\Middleware\Admin::class, //added line
  ];
  </code></pre>
  
  <p>I also defined isAdmin() in my user model. It works when I do this in the route:</p>
  
  <pre><code>get('protected', ['middleware' =&gt; ['auth', 'admin'], function() {
      return "this page requires that you be logged in and an Admin";
  }]);
  </code></pre>
  
  <p>But I want to use it like Auth::admin() as Auth::guest(), where should I implement this function? Do I need a  abstract admin() in Guard.php first?</p>
  
  <p>I can get around with Auth::user()->isAdmin(), but I still want to know the right way to do it.</p>
  
  <p>Thanks.</p>
  
  <p>Thanks.</p>