php - 尝试在 Laravel 中使用 JWTAuth 创建用户时出错
问题描述
我正在尝试制作一个简单的身份验证 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 测试测试和高级 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)
推荐阅读
- node.js - 从模型定义更新迁移文件的 NodeJS ORM 框架
- xpath - 无法导航并单击系统选项卡下的“全部”单选按钮,因为页面中的其他选项卡下有多个名称为 ALL 的单选按钮
- c# - Content-Length 随机为空
- javascript - Javascript:使用函数将变量更改为真/假
- ruby-on-rails - 如何从另一个控制器部分访问实例变量
- asp.net - Visual Studio 2012 ASP.NET 设计页面无法识别印地语字符
- c# - 等待服务器响应 PostAsJsonAsync
- java - Selenium WebDriver – 如何在这个复杂的网站上自动化 DatePicker?
- android - 如何在 Delphi 中使用 Intent 拨打电话?
- vba - 列出/获取 Outlook 中的所有 SentOnBehalfNames