title: Laravel-5 adding hasRole method to Auth
body: <p>I'm trying to extend the Laravel-5.1 <code>Auth</code> middleware so that I can add my own method to it:</p>
  
  <p><code>Auth::hasRole()</code></p>
  
  <p>What do I need to do in order to add the new method hasRole to Auth?</p>
  
  <p>Here is my routes file:</p>
  
  <pre><code>/* Administrator Routes */
  
  Route::group(['namespace' =&gt; 'Admin', 'middleware' =&gt; 'timesheets.admin:Administrator'], function()
  {
      Route::get('home', 'AdminController@index');
  });
  </code></pre>
  
  <p>Here is my middleware file:</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Middleware\Auth;
  
  use Closure;
  use Illuminate\Contracts\Auth\Guard;
  
  class AdminAuthenticate
  {
      /**
       * The Guard implementation.
       *
       * @var Guard
       */
      protected $auth;
  
      /**
       * Create a new filter instance.
       *
       * @param  Guard  $auth
       * @return void
       */
      public function __construct(Guard $auth)
      {
          $this-&gt;auth = $auth;
      }
  
      /**
       * Handle an incoming request.
       *
       * @param  \Illuminate\Http\Request  $request
       * @param  \Closure  $next
       * @return mixed
       */
      public function handle($request, Closure $next, $role)
      {
          if ($this-&gt;auth-&gt;guest()) {
              if ($request-&gt;ajax()) {
                  return response('Unauthorized.', 401);
              } else {
                  return redirect()-&gt;guest('login');
              }
          }
  
          if (auth()-&gt;check() &amp;&amp; auth()-&gt;user()-&gt;hasRole($role)) {
              return $next($request);
          }
  
      }
  }
  </code></pre>