title: Undefined type Laravel\Sanctum\HasApiTokens in Laravel 8
body: <p>Need someone to help me with this issue. Laravel Sanctum</p>
  <p>I've installed basic default laravel 8++ on my local server.</p>
  <p>I follow the instruction of Laravel Sanctum. But I stuck on getting the <strong>HasApiTokens</strong></p>
  <pre><code>1. composer require laravel/sanctum
  2. php artisan vendor:publish --provider=&quot;Laravel\Sanctum\SanctumServiceProvider&quot;
  3. php artisan migrate
  </code></pre>
  <p>I add in my <strong>kernel.php</strong> like below</p>
  <pre><code>use Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful;
  
  'api' =&gt; [
      EnsureFrontendRequestsAreStateful::class,
      'throttle:api',
      \Illuminate\Routing\Middleware\SubstituteBindings::class,
  ],
  </code></pre>
  <p>And in <strong>config&gt;auth.php</strong>, I changed the driver to 'sanctum'</p>
  <pre><code> 'guards' =&gt; [
          'web' =&gt; [
              'driver' =&gt; 'session',
              'provider' =&gt; 'users',
          ],
  
          'api' =&gt; [
              'driver' =&gt; 'sanctum',
              'provider' =&gt; 'users',
              'hash' =&gt; false,
          ], 
      ],
  </code></pre>
  <p>And here's my <strong>composer.json</strong></p>
  <pre><code>{
      &quot;name&quot;: &quot;laravel/laravel&quot;,
      &quot;type&quot;: &quot;project&quot;,
      &quot;description&quot;: &quot;The Laravel Framework.&quot;,
      &quot;keywords&quot;: [
          &quot;framework&quot;,
          &quot;laravel&quot;
      ],
      &quot;license&quot;: &quot;MIT&quot;,
      &quot;require&quot;: {
          &quot;php&quot;: &quot;^7.3|^8.0&quot;,
          &quot;fideloper/proxy&quot;: &quot;^4.4&quot;,
          &quot;fruitcake/laravel-cors&quot;: &quot;^2.0&quot;,
          &quot;guzzlehttp/guzzle&quot;: &quot;^7.2&quot;,
          &quot;laravel/framework&quot;: &quot;^8.12&quot;,
          &quot;laravel/passport&quot;: &quot;^10.1&quot;,
          &quot;laravel/sanctum&quot;: &quot;^2.9&quot;,
          &quot;laravel/tinker&quot;: &quot;^2.5&quot;,
          &quot;symfony/psr-http-message-bridge&quot;: &quot;^2.0&quot;
      },
      &quot;require-dev&quot;: {
          &quot;facade/ignition&quot;: &quot;^2.5&quot;,
          &quot;fakerphp/faker&quot;: &quot;^1.9.1&quot;,
          &quot;laravel/sail&quot;: &quot;^1.0.1&quot;,
          &quot;mockery/mockery&quot;: &quot;^1.4.2&quot;,
          &quot;nunomaduro/collision&quot;: &quot;^5.0&quot;,
          &quot;phpunit/phpunit&quot;: &quot;^9.3.3&quot;
      },
      &quot;config&quot;: {
          &quot;optimize-autoloader&quot;: true,
          &quot;preferred-install&quot;: &quot;dist&quot;,
          &quot;sort-packages&quot;: true
      },
      &quot;extra&quot;: {
          &quot;laravel&quot;: {
              &quot;dont-discover&quot;: []
          }
      },
      &quot;autoload&quot;: {
          &quot;psr-4&quot;: {
              &quot;App\\&quot;: &quot;app/&quot;,
              &quot;Database\\Factories\\&quot;: &quot;database/factories/&quot;,
              &quot;Database\\Seeders\\&quot;: &quot;database/seeders/&quot;
          }
      },
      &quot;autoload-dev&quot;: {
          &quot;psr-4&quot;: {
              &quot;Tests\\&quot;: &quot;tests/&quot;
          }
      },
      &quot;minimum-stability&quot;: &quot;dev&quot;,
      &quot;prefer-stable&quot;: true,
      &quot;scripts&quot;: {
          &quot;post-autoload-dump&quot;: [
              &quot;Illuminate\\Foundation\\ComposerScripts::postAutoloadDump&quot;,
              &quot;@php artisan package:discover --ansi&quot;
          ],
          &quot;post-root-package-install&quot;: [
              &quot;@php -r \&quot;file_exists('.env') || copy('.env.example', '.env');\&quot;&quot;
          ],
          &quot;post-create-project-cmd&quot;: [
              &quot;@php artisan key:generate --ansi&quot;
          ]
      }
  }
  </code></pre>
  <p>But when I tried to import/use Laravel/Sanctum/HasApiTokens, it says '<strong>undefined type</strong>'. Image as below</p>
  <p><a href="https://i.stack.imgur.com/n8KsJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/n8KsJ.png" alt="enter image description here" /></a></p>
  <p>Here's another screenshot. Doesn't have any sanctum directory after Laravel.</p>
  <p><a href="https://i.stack.imgur.com/4SeOU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4SeOU.png" alt="enter image description here" /></a></p>