title: Laravel 6: Call to undefined method App\\User::createToken()
body: <p>I'm trying to generate a token to authenticate users in my Controller the following way:</p>
  
  <pre><code>namespace App\Http\Controllers\API;
  use Illuminate\Foundation\Auth\AuthenticatesUsers;
  use Illuminate\Http\Request;
  
  use App\Http\Controllers\Controller;
  use Illuminate\Support\Facades\Auth;
  use App\Models\User;
  
  class AuthController extends Controller
  {
      public function login()
      {
          if (Auth::attempt(['email' =&gt; request('email'), 'password' =&gt; request('password')])) {
              $user = Auth::user();
  
  
              $success['token'] = $user-&gt;createToken('myApp')-&gt;accessToken;
              dd($success['token']);
  
          }
      }
  </code></pre>
  
  <p>Currently, I'm just trying to print out the token. And this is my User's model:</p>
  
  <pre><code>&lt;?php
  
  namespace App\Models;
  
  use Illuminate\Notifications\Notifiable;
  //use Illuminate\Contracts\Auth\MustVerifyEmail;
  use Illuminate\Foundation\Auth\User as Authenticatable;
  use Illuminate\Support\Facades\Hash;
  use Laravel\Passport\HasApiTokens;
  
  class User extends Authenticatable
  {
      use HasApiTokens, Notifiable;
  
      const USER_FIRST_NAME_FIELD        = "first_name";
      const USER_LAST_NAME_FIELD         = "last_name";
      const USER_PREFERRED_NAME_FIELD    = "preferred_name";
      const USER_EMAIL_FIELD             = "email";
      const USER_EMAIL_VERIFIED_AT_FIELD = "email_verified_at";
      const USER_PASSWORD_FIELD          = "password";
      const USER_REMEMBER_TOKEN_FIELD    = "remember_token";
      const USER_RECEIVE_NEWSLETTER_FIELD= "receive_newsletter";
      const USER_ACTIVE_FIELD            = "active";
  
      /**
       * The attributes that are mass assignable.
       *
       * @var array
       */
      protected $fillable = [
          self::USER_FIRST_NAME_FIELD, 
          self::USER_LAST_NAME_FIELD,
          self::USER_PREFERRED_NAME_FIELD,
          self::USER_EMAIL_FIELD,
          self::USER_PASSWORD_FIELD,
          self::USER_RECEIVE_NEWSLETTER_FIELD,
          self::USER_ACTIVE_FIELD,
      ];
  
      /**
       * The attributes that should be hidden for arrays.
       *
       * @var array
       */
      protected $hidden = [
          self::USER_PASSWORD_FIELD,
          self::USER_REMEMBER_TOKEN_FIELD
      ];
  
      /**
       * Automatically creates password hash when password is submitted
       *
       * @param string $password
       * @return void
       */
      public function setPasswordAttribute(string $password) : void
      {
          $this-&gt;attributes['password'] = Hash::make($password);    
      }
  }
  </code></pre>
  
  <p>As you can see I'm using <code>HasApiTokens, Notifiable</code> traits and nonetheless I'm getting an error from my controller saying:</p>
  
  <blockquote>
    <p>Call to undefined method App\User::createToken()</p>
  </blockquote>
  
  <p>Passport is installed and configured correctly.</p>
  
  <p><strong>Here's something weird:</strong></p>
  
  <p>When registering an user (I'm using a separate controller and also using a service) a token is created successfully:</p>
  
  <p>Here's my controller:</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers\API;
  
  use App\Services\UserService;
  use Illuminate\Http\JsonResponse;
  use App\Http\Controllers\Controller;
  use App\Http\Requests\RegisterUserRequest;
  
  
  class UserController extends Controller 
  {
      private $user;
  
      public function __construct(UserService $user)
      {
          $this-&gt;user = $user;
      }
  
      public function store(RegisterUserRequest $request) : JsonResponse
      {
          // TODO: verify message on error
  
          $user = $this-&gt;user-&gt;register($request-&gt;validated());
          $token = $user-&gt;createToken('MyApp')-&gt;accessToken;
          dd($token);
  
          return response()-&gt;json(['status' =&gt; 201, 'user_id' =&gt; $user-&gt;id]);
      }
  
  }
  </code></pre>
  
  <p>Here's my service:</p>
  
  <pre><code>&lt;?php
  
  namespace App\Services;
  
  use App\Models\User;
  use App\Services\BaseServiceInterface;
  
  class UserService implements BaseServiceInterface
  {
  
      public function register(array $formValues) : User
      {
          // 'terms and conditions' should not be saved into the db, hence it's removed
          unset($formValues['terms_conditions']);
          return User::create($formValues);
      }
  
  }
  </code></pre>
  
  <p>and here's my model again:</p>
  
  <pre><code>&lt;?php
  
  namespace App\Models;
  
  use Illuminate\Notifications\Notifiable;
  //use Illuminate\Contracts\Auth\MustVerifyEmail;
  use Illuminate\Foundation\Auth\User as Authenticatable;
  use Illuminate\Support\Facades\Hash;
  use Laravel\Passport\HasApiTokens;
  
  class User extends Authenticatable
  {
      use HasApiTokens, Notifiable;
  
      const USER_FIRST_NAME_FIELD        = "first_name";
      const USER_LAST_NAME_FIELD         = "last_name";
      const USER_PREFERRED_NAME_FIELD    = "preferred_name";
      const USER_EMAIL_FIELD             = "email";
      const USER_EMAIL_VERIFIED_AT_FIELD = "email_verified_at";
      const USER_PASSWORD_FIELD          = "password";
      const USER_REMEMBER_TOKEN_FIELD    = "remember_token";
      const USER_RECEIVE_NEWSLETTER_FIELD= "receive_newsletter";
      const USER_ACTIVE_FIELD            = "active";
  
      /**
       * The attributes that are mass assignable.
       *
       * @var array
       */
      protected $fillable = [
          self::USER_FIRST_NAME_FIELD, 
          self::USER_LAST_NAME_FIELD,
          self::USER_PREFERRED_NAME_FIELD,
          self::USER_EMAIL_FIELD,
          self::USER_PASSWORD_FIELD,
          self::USER_RECEIVE_NEWSLETTER_FIELD,
          self::USER_ACTIVE_FIELD,
      ];
  
      /**
       * The attributes that should be hidden for arrays.
       *
       * @var array
       */
      protected $hidden = [
          self::USER_PASSWORD_FIELD,
          self::USER_REMEMBER_TOKEN_FIELD
      ];
  
  </code></pre>
  
  <p>As I told you, when creating a user the token is being generated correctly. </p>
  
  <p>I'd say that <code>Auth::user()</code> is not calling my Model directly, but I don't know for sure that's what is happening.</p>
  
  <p>Any idea why?
  Thanks</p>