我正在运行流明(5.6.3)(Laravel Components 5.6。*)。我正在尝试使用本教程(https://www.youtube.com/watch?v=eWoJ2YbdrWU&t=5s)构建Rest api。这是我的games.php代码:
<?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'];
}
跑步后得到的错误是:
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
我做了与教程相同的一切。我无法在第2部分解决此错误。
答案 0 :(得分:4)
composer require laravel/passport
php artisan passport:install
Laravel\Passport\HasApiTokens
特征添加App\User
特征。再试一次。
答案 1 :(得分:0)
您必须包括“使用Laravel \ Passport \ HasApiTokens;”在用户模型的顶部。
答案 2 :(得分:0)
将Laravel \ Passport \ HasApiTokens特性添加到您的App \ User模型。此特征将为您的模型提供一些辅助方法,使您可以检查经过身份验证的用户的令牌和范围:
namespace App;
use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use HasApiTokens, Notifiable;
}