title: Laravel Auth simple API always returning Unauthorized 401 error
body: <p>This is driving me crazy... All is suppossed to be correct and im ALWAYS getting unauthorized error in my API routes!!</p>
  
  <p>Api.php routes:</p>
  
  <pre><code>Route::middleware('auth:api')-&gt;get('/user', function (Request $request) {
  return $request-&gt;user();
  </code></pre>
  
  <p>});</p>
  
  <p>RegisterController:</p>
  
  <pre><code>    protected function create(array $data)
  {
      return User::create([
          'name' =&gt; $data['name'],
          'email' =&gt; $data['email'],
          'password' =&gt; Hash::make($data['password']),
          'api_token' =&gt; Str::random(80),
      ]);
  }
  </code></pre>
  
  <p><strong>Database</strong>:</p>
  
  <p><a href="https://i.stack.imgur.com/EOJxs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EOJxs.png" alt="enter image description here"></a></p>
  
  <p><strong>Request</strong>:</p>
  
  <p><a href="https://i.stack.imgur.com/xKirF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xKirF.png" alt="enter image description here"></a></p>
  
  <p>Accept application/json is set:</p>
  
  <p><a href="https://i.stack.imgur.com/fDw7L.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fDw7L.png" alt="enter image description here"></a></p>
  
  <p>I tried too using jquery to make the request with a query parameter api_key but it doesnt work either!!</p>
  
  <p>I searched a lot and can't solve this. I have another fresh application with Laravel and auth and it works perfect but this project is old and i recently updated it to Laravel 7 and I don't know why this dont works.</p>
  
  <p>More info:</p>
  
  <p>Im using php artisan serve to serve the application.</p>
  
  <p>My kernel.php:</p>
  
  <pre><code>&lt;?php
  </code></pre>
  
  <p>namespace App\Http;</p>
  
  <p>use Illuminate\Foundation\Http\Kernel as HttpKernel;</p>
  
  <p>class Kernel extends HttpKernel
  {
      /**
       * The application's global HTTP middleware stack.
       *
       * These middleware are run during every request to your application.
       *
       * @var array
       */
      protected $middleware = [
          \App\Http\Middleware\TrustProxies::class,
          \App\Http\Middleware\CheckForMaintenanceMode::class,
          \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
          \App\Http\Middleware\TrimStrings::class,
          \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
      ];</p>
  
  <pre><code>/**
   * The application's route middleware groups.
   *
   * @var array
   */
  protected $middlewareGroups = [
      'web' =&gt; [
          \App\Http\Middleware\EncryptCookies::class,
          \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
          \Illuminate\Session\Middleware\StartSession::class,
          // \Illuminate\Session\Middleware\AuthenticateSession::class,
          \Illuminate\View\Middleware\ShareErrorsFromSession::class,
          \App\Http\Middleware\VerifyCsrfToken::class,
          \Illuminate\Routing\Middleware\SubstituteBindings::class,
      ],
  
      'api' =&gt; [
          'throttle:60,1',
          'bindings',
          'auth:api',
      ],
  ];
  
  /**
   * The application's route middleware.
   *
   * These middleware may be assigned to groups or used individually.
   *
   * @var array
   */
  protected $routeMiddleware = [
      'auth' =&gt; \App\Http\Middleware\Authenticate::class,
      'auth.basic' =&gt; \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
      'bindings' =&gt; \Illuminate\Routing\Middleware\SubstituteBindings::class,
      'cache.headers' =&gt; \Illuminate\Http\Middleware\SetCacheHeaders::class,
      'can' =&gt; \Illuminate\Auth\Middleware\Authorize::class,
      'guest' =&gt; \App\Http\Middleware\RedirectIfAuthenticated::class,
      'password.confirm' =&gt; \Illuminate\Auth\Middleware\RequirePassword::class,
      'signed' =&gt; \Illuminate\Routing\Middleware\ValidateSignature::class,
      'throttle' =&gt; \Illuminate\Routing\Middleware\ThrottleRequests::class,
      'verified' =&gt; \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
      'language' =&gt; \App\Http\Middleware\GetRequestLanguage::class,
      'setLocale' =&gt; \App\Http\Middleware\SetLocale::class,
  ];
  
  /**
   * The priority-sorted list of middleware.
   *
   * This forces non-global middleware to always be in the given order.
   *
   * @var array
   */
  protected $middlewarePriority = [
      \Illuminate\Session\Middleware\StartSession::class,
      \Illuminate\View\Middleware\ShareErrorsFromSession::class,
      \App\Http\Middleware\Authenticate::class,
      \Illuminate\Routing\Middleware\ThrottleRequests::class,
      \Illuminate\Session\Middleware\AuthenticateSession::class,
      \Illuminate\Routing\Middleware\SubstituteBindings::class,
      \Illuminate\Auth\Middleware\Authorize::class,
  ];
  </code></pre>
  
  <p>}</p>
  
  <p>Thank's you... I hope you can help me...</p>