trait 'App\HasApiTokens' not found in Lumen
15,511
Solution 1
Do you have composer? Install that first. Then you need Laravel Passport.
- Run
composer require laravel/passport
- Run
php artisan passport:install
from command line - Add add the
Laravel\Passport\HasApiTokens
trait to yourApp\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;
}
Author by
Hanna
Updated on July 20, 2022Comments
-
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.