在 Laravel 中尝试使用 JWTAuth 创建用户时出错
Error when trying to create an user with JWTAuth in Laravel
我正在尝试创建一个简单的身份验证 API 以使用 PHP 和 Laravel 获取带有 JWTAuth 的令牌,但每次尝试创建用户:
[Tue Oct 6 07:21:21 2020] 127.0.0.1:56819 Accepted
[Tue Oct 6 07:21:22 2020] 127.0.0.1:56819 Closing
[Tue Oct 6 07:21:31 2020] 127.0.0.1:56820 Accepted
[Tue Oct 6 07:21:31 2020] PHP Fatal error: Class App\Models\User contains 1 abstract method and must
therefore be declared abstract or implement the remaining methods (Tymon\JWTAuth\Contracts\JWTSubject::getJWTCustomClaims)
in E:\_Code\laravel\ApiDevBarber\app\Models\User.php on line 10
[Tue Oct 6 07:21:33 2020] 127.0.0.1:56820 Closing
Insomnia、Rest test 和 Advanced REST 客户端都会出现此错误。我已经按照 Laravel 和 JWT 文档编写了 User.php,下面是完整代码。
<?php
namespace App\Models;
use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable implements JWTSubject
{
use Notifiable;
protected $hidden = ['password'];
public $timestamps = false;
public function getJWTIdentifier() {
return $this->getkey();
}
public function getJWTCustomClains() {
return [];
}
}
我是 PHP 和 Laravel 的新人,我错过了什么吗?
您的方法 getJWTCustomClaims(而不是 getJWTCustomClains)有错误
我正在尝试创建一个简单的身份验证 API 以使用 PHP 和 Laravel 获取带有 JWTAuth 的令牌,但每次尝试创建用户:
[Tue Oct 6 07:21:21 2020] 127.0.0.1:56819 Accepted
[Tue Oct 6 07:21:22 2020] 127.0.0.1:56819 Closing
[Tue Oct 6 07:21:31 2020] 127.0.0.1:56820 Accepted
[Tue Oct 6 07:21:31 2020] PHP Fatal error: Class App\Models\User contains 1 abstract method and must
therefore be declared abstract or implement the remaining methods (Tymon\JWTAuth\Contracts\JWTSubject::getJWTCustomClaims)
in E:\_Code\laravel\ApiDevBarber\app\Models\User.php on line 10
[Tue Oct 6 07:21:33 2020] 127.0.0.1:56820 Closing
Insomnia、Rest test 和 Advanced REST 客户端都会出现此错误。我已经按照 Laravel 和 JWT 文档编写了 User.php,下面是完整代码。
<?php
namespace App\Models;
use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable implements JWTSubject
{
use Notifiable;
protected $hidden = ['password'];
public $timestamps = false;
public function getJWTIdentifier() {
return $this->getkey();
}
public function getJWTCustomClains() {
return [];
}
}
我是 PHP 和 Laravel 的新人,我错过了什么吗?
您的方法 getJWTCustomClaims(而不是 getJWTCustomClains)有错误