title: Call to undefined method App\Models\User::createToken()
body: <p>I'm new to Laravel and i'm getting this error: <strong>Call to undefined method App\Models\User::createToken()</strong></p>
  <p><code>Laravel Framework 8.34.0</code>
  <code>PHP 7.4.3</code></p>
  <p>My Controller:</p>
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  use Illuminate\Http\Request;
  use Illuminate\Support\Facades\Validator;
  use Illuminate\Support\Facades\Auth;
  use App\Models\User;
  
  class UserController extends Controller
  {
     private $sucess_status = 200;
  
     public function createUser(Request $request){
         $validator = Validator::make($request-&gt;all(),
         [
             'first_name' =&gt; 'required',
             'last_name' =&gt; 'required',
             'phone' =&gt; 'required|numeric',
             'email' =&gt; 'required|email',
             'password' =&gt; 'required|alpha_num|min:5'
         ]
      );
  
          if($validator-&gt;fails()){
              return response()-&gt;json([&quot;validattion_errors&quot;=&gt;$validator-&gt;errors()]);
          }
  
          $dataArray = array(
              &quot;first_name&quot;=&gt;$request-&gt;first_name,
              &quot;last_name&quot;=&gt;$request-&gt;last_name,
              &quot;full_name&quot;=&gt;$request-&gt;first_name . &quot; &quot; . $request-&gt;last_name,
              &quot;phone&quot;=&gt;$request-&gt;phone,
              &quot;email&quot;=&gt;$request-&gt;email,
              &quot;password&quot;=&gt;bcrypt($request-&gt;password),
  
          );
  
          $user = User::create($dataArray);
          if(!is_null($user)){
              return response()-&gt;json([&quot;status&quot; =&gt; $this-&gt;sucess_status, &quot;success&quot; =&gt; true, &quot;data&quot; =&gt; $user]);
          }else {
              return response()-&gt;json([&quot;status&quot; =&gt; &quot;failed&quot;, &quot;success&quot; =&gt; false, &quot;message&quot; =&gt; &quot;User not created&quot;]);
          }
     }
  
     public function userLogin(Request $request){
         $validator = Validator::make($request-&gt;all(),
         [
             'email' =&gt; 'required|email',
             'password' =&gt; 'required|alpha_num|min:5'
         ]
      );
  
      if($validator-&gt;fails()){
          return response()-&gt;json([&quot;validation_errors&quot;=&gt;$validator-&gt;errors()]);
      }
  
      if(Auth::attempt(['email' =&gt; $request-&gt;email, 'password' =&gt; $request-&gt;password])){
          $user = Auth::user();
          $token = $user-&gt;createToken('token')-&gt;accessToken;
          return response()-&gt;json([&quot;status&quot; =&gt; $this-&gt;sucess_status, &quot;success&quot; =&gt; true, &quot;login&quot; =&gt; true, &quot;token&quot; =&gt; $token, &quot;data&quot; =&gt; $user]);
      } else{
          return response()-&gt;json([&quot;status&quot; =&gt; &quot;failed&quot;, &quot;success&quot; =&gt; false, &quot;message&quot; =&gt; &quot;Invalid email or password&quot;]);
      }
     }
  
     public function userDetail(){
         $user = Auth::user();
         if(!is_null($user)){
          return response()-&gt;json([&quot;status&quot; =&gt; $this-&gt;sucess_status, &quot;success&quot; =&gt; true, &quot;user&quot; =&gt; $user]);
         }else {
          return response()-&gt;json([&quot;status&quot; =&gt; &quot;failed&quot;, &quot;success&quot; =&gt; false, &quot;message&quot; =&gt; &quot;No user found&quot;]);
      }
     }
  }
  </code></pre>
  <p>My Auth.php:</p>
  <pre><code>&lt;?php
  
  return [
  
      /*
      |--------------------------------------------------------------------------
      | Authentication Defaults
      |--------------------------------------------------------------------------
      |
      | This option controls the default authentication &quot;guard&quot; and password
      | reset options for your application. You may change these defaults
      | as required, but they're a perfect start for most applications.
      |
      */
  
      'defaults' =&gt; [
          'guard' =&gt; 'web',
          'passwords' =&gt; 'users',
      ],
  
      /*
      |--------------------------------------------------------------------------
      | Authentication Guards
      |--------------------------------------------------------------------------
      |
      | Next, you may define every authentication guard for your application.
      | Of course, a great default configuration has been defined for you
      | here which uses session storage and the Eloquent user provider.
      |
      | All authentication drivers have a user provider. This defines how the
      | users are actually retrieved out of your database or other storage
      | mechanisms used by this application to persist your user's data.
      |
      | Supported: &quot;session&quot;, &quot;token&quot;
      |
      */
  
      'guards' =&gt; [
          'web' =&gt; [
              'driver' =&gt; 'session',
              'provider' =&gt; 'users',
          ],
  
          'api' =&gt; [
              'driver' =&gt; 'passport',
              'provider' =&gt; 'users',
              'hash' =&gt; false,
          ],
      ],
  
      /*
      |--------------------------------------------------------------------------
      | User Providers
      |--------------------------------------------------------------------------
      |
      | All authentication drivers have a user provider. This defines how the
      | users are actually retrieved out of your database or other storage
      | mechanisms used by this application to persist your user's data.
      |
      | If you have multiple user tables or models you may configure multiple
      | sources which represent each model / table. These sources may then
      | be assigned to any extra authentication guards you have defined.
      |
      | Supported: &quot;database&quot;, &quot;eloquent&quot;
      |
      */
  
      'providers' =&gt; [
          'users' =&gt; [
              'driver' =&gt; 'eloquent',
              'model' =&gt; App\Models\User::class,
          ],
  
          // 'users' =&gt; [
          //     'driver' =&gt; 'database',
          //     'table' =&gt; 'users',
          // ],
      ],
  
      /*
      |--------------------------------------------------------------------------
      | Resetting Passwords
      |--------------------------------------------------------------------------
      |
      | You may specify multiple password reset configurations if you have more
      | than one user table or model in the application and you want to have
      | separate password reset settings based on the specific user types.
      |
      | The expire time is the number of minutes that the reset token should be
      | considered valid. This security feature keeps tokens short-lived so
      | they have less time to be guessed. You may change this as needed.
      |
      */
  
      'passwords' =&gt; [
          'users' =&gt; [
              'provider' =&gt; 'users',
              'table' =&gt; 'password_resets',
              'expire' =&gt; 60,
              'throttle' =&gt; 60,
          ],
      ],
  
      /*
      |--------------------------------------------------------------------------
      | Password Confirmation Timeout
      |--------------------------------------------------------------------------
      |
      | Here you may define the amount of seconds before a password confirmation
      | times out and the user is prompted to re-enter their password via the
      | confirmation screen. By default, the timeout lasts for three hours.
      |
      */
  
      'password_timeout' =&gt; 10800,
  
  ];
  </code></pre>
  <p>I had run the <code>php artisan passport: install</code> command 3 times
  because I forgot to save the file with the settings and I thought it would be necessary to run the code again after saving the file</p>
  <p>And returned me this:</p>
  <pre><code>Encryption keys already exist. Use the --force option to overwrite them.
  Personal access client created successfully.
  Client ID: 3
  Client secret: JoZbAGCSOZ6t0hn7YnnT6PdN4EMUUZa7H1vU6Sk2
  Password grant client created successfully.
  Client ID: 4
  Client secret: yAxjrBnvPWCiAdXod5FmJDQTNDmneRoO1LtM6B0x
  cristiansto in Laravel/API/todoList 
  ❯ php artisan passport:install --force
  Encryption keys generated successfully.
  Personal access client created successfully.
  Client ID: 5
  Client secret: 8CtWyvXIwapZnfO5dTGDsyF0iXvJsxNyiZeUksTL
  Password grant client created successfully.
  Client ID: 6
  Client secret: 9jThPxOfgNxJINFKIbDz0WU5yYEup0pIkboEJLr0
  cristiansto in Laravel/API/todoList 
  </code></pre>
  <p>I dont know if this is the cause.</p>
  <p>What could it be?</p>