trait 'App\HasApiTokens' not found in Lumen

15,511

Solution 1

Do you have composer? Install that first. Then you need Laravel Passport.

  1. Run composer require laravel/passport
  2. Run php artisan passport:install from command line
  3. Add add the Laravel\Passport\HasApiTokens trait to your App\User model.

Try again.

Solution 2

You must include this "use Laravel\Passport\HasApiTokens;" at the top in your user model.

Solution 3

Add the Laravel\Passport\HasApiTokens trait to your App\User model. This trait will provide a few helper methods to your model which allow you to inspect the authenticated user's token and scopes:

namespace App;

use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use HasApiTokens, Notifiable;
}
Share:
15,511
Hanna
Author by

Hanna

Updated on July 20, 2022

Comments

  • Hanna
    Hanna almost 2 years

    I am running Lumen (5.6.3) (Laravel Components 5.6.*). I'm trying to build a Rest api using this tutorial(https://www.youtube.com/watch?v=eWoJ2YbdrWU&t=5s). Here is my games.php code:

    <?php 
    
    namespace App;
    
    use Illuminate\Foundation\Auth\User as Authenticatable;
    use Illuminate\Database\Eloquent\SoftDeletes;
    use Bican\Roles\Traits\HasRoleAndPermission;
    use Bican\Roles\Contracts\HasRoleAndPermission as HasRoleAndPermissionContract;
    
    use Illuminate\Database\Eloquent\Model;
    
    class games extends Model implements AuthenticatableContract, AuthenticatableContract, HasRoleAndPermissionContract
    { 
        use HasApiTokens, Authenticatable, Authorizable;
        protected $table="games";
    
        protected $fillable = ['Team 1','Team 2','Score 1','Score 2','Game Date','Viewers'];     
    }
    

    The error I get after running is:

    PHP Fatal error:  Trait 'App\HasApiTokens' not found in C:\Users...lumen-api\app\games.php on line 14
    
    Fatal error: Trait 'App\HasApiTokens' not found in C:\Users\...lumen-api\app\games.php on line 14
    
    In games.php line 14:
    
      Trait 'App\HasApiTokens' not found
    

    I did everything the same as the tutorial. I can't solve this error in part 2.