Argument 1 passed to Tymon\JWTAuth\JWTGuard::login() must be an ....
简介
Argument 1 passed to Tymon\JWTAuth\JWTGuard::login() must be an instance of Tymon\JWTAuth\Contracts\JWTSubject, instance of App\Models\User given, called in......
在使用jwt-auth做登录认证的时候为什么报这个错误,出现如下报错:
Symfony\Component\Debug\Exception\FatalThrowableError: Argument 1 passed to Tymon\JWTAuth\JWTGuard::login() must be an instance of Tymon\JWTAuth\Contracts\JWTSubject, instance of App\Models\User given, called in E:\wwwroot\laravel\dev.lar.net\vendor\tymon\jwt-auth\src\JWTGuard.php on line 127 in file E:\wwwroot\laravel\dev.lar.net\vendor\tymon\jwt-auth\src\JWTGuard.php on line 140
解决方法:
修改User.php模型
改成
<?php
//...
use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Facades\Auth;
class User extends Authenticatable implements JWTSubject
{
use Notifiable;
public function getJWTIdentifier()
{
return $this->getKey();
}
public function getJWTCustomClaims()
{
return [];
}
//...