title: In Laravel 5.7, How to override Tymon Jwt-Auth Middleware in Kernel?
body: <p>I'm using Laravel 5.7 for some api. I'm also using package <a href="https://github.com/tymondesigns/jwt-auth" rel="nofollow noreferrer">https://github.com/tymondesigns/jwt-auth</a> to generate JWT tokens to authenticate users. I have configured everything long time ago and it works well.</p>
  
  <p>I register Route group in <code>RouteServiceProvider.php</code> under <code>routes/api_v1.php</code> :</p>
  
  <pre><code>Route::prefix('api/v1')
       -&gt;middleware('api')
       -&gt;namespace($this-&gt;namespace.'\API\V1')
       -&gt;group(base_path('routes/api_v1.php'));
  </code></pre>
  
  <p>In <code>config.auth.php</code> I have api_v1 guard with driver jwt :</p>
  
  <pre><code>'guards' =&gt; [
      'web' =&gt; [
          'driver' =&gt; 'session',
          'provider' =&gt; 'users',
      ],
  
      'api_v1' =&gt; [
          'driver' =&gt; 'jwt',
          'provider' =&gt; 'users',
      ],
  ],
  </code></pre>
  
  <p>I have made <code>App/User.php</code> implemented <code>Tymon\JWTAuth\Contracts\JWTSubject</code> and implemented the 2 methods.</p>
  
  <p>But when in <code>app/Http/Kernel.php</code> I added in middlewares array :</p>
  
  <pre><code>protected $routeMiddleware = [
      // previous middlewares,
      'jwt.auth' =&gt; \App\Http\Middleware\JWTAuthenticate::class
  ];
  </code></pre>
  
  <p>The Routes in <code>routes/api_v1.php</code> under the group <code>jwt.auth</code>:</p>
  
  <p>Route::middleware(['jwt.auth'])->group(function() {</p>
  
  <pre><code>// Keep auto resource route at bottom to prevent route conflict with Show parameter route
  foreach(Controller::$resourceModels as $key =&gt; $model) {
      //Route::post($key.'/{id}/patch', $model.'Controller@patchUpdate');
      Route::resource($key, $model.'Controller');
  }
  </code></pre>
  
  <p>});</p>
  
  <p>never reach middleware <code>App\Http\Middleware\JWTAuthenticate::class</code> but always go to the original tymon package middleware <code>Tymon\JWTAuth\Http\Middleware\Authenticate::class</code>.</p>
  
  <p>Even if I don't put api driver to jwt in <code>auth.php</code> config, and I don't put any <code>jwt.auth</code> class in Middleware it's working normally with original middleware.</p>
  
  <p>What I need is for the Routes group to go to my own middleware class <code>App/Http/Middlewares/JWTAuthenticate</code> :</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Middleware;
  
  use Tymon\JWTAuth\Http\Middleware\Authenticate;
  
  use Closure;
  
  class JWTAuthenticate extends Authenticate
  {
      /**
       * Handle an incoming request.
       *
       * @param  \Illuminate\Http\Request  $request
       * @param  \Closure  $next
       *
       * @throws \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
       *
       * @return mixed
       */
      public function handle($request, Closure $next)
      {
          // My own logics here
          // ...
  
  
          $this-&gt;authenticate($request);
  
          return $next($request);
      }
  }
  </code></pre>
  
  <p>and this way I can override <code>handle</code> method and check for my own things first.</p>