【发布时间】:2020-12-15 22:52:26
【问题描述】:
我是 laravel 的新手,我打算对我的 API 调用进行身份验证。就这样吧……
我已经按照 guide 在 laravel 上设置 jwt-auth 的步骤进行了操作
安装后,我在composer.json中更改了jwt-auth版本,运行composer update
"require": { "php": "^7.2.5", "fideloper/proxy": "^4.2", "fruitcake/laravel-cors": "^2.0", "guzzlehttp/guzzle": "^6.3", "laravel/framework": "^7.24", "laravel/tinker": "^2.0", "tymon/jwt-auth": "^1.0.0-rc.5.1" //Originally "^1.0" },
我不知道这是否是原因,但是,在我的 User.php 模型中,我无法实现 JWTSubject
这是 User.php 模型:
<?php namespace App; use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Tymon\JWTAuth\Contracts\JWTSubject; class User extends Authenticatable implements App\JWTSubject //It says 'undefined type App\App\JWTSubject { use Notifiable; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'name', 'email', 'password', ]; /** * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; /** * The attributes that should be cast to native types. * * @var array */ protected $casts = [ 'email_verified_at' => 'datetime', ]; }
更新:发现新问题:
我决定继续阅读指南,但是,在创建 AuthController.php 之后,我注意到 attempt、logout、refresh 和 factory 方法有错误说 undefined method。
【问题讨论】: