FatalThrowableError:Argument 1 passed ..::fromUser() laravel 5.6(FatalThrowableError:参数 1 已通过 ..::fromUser() laravel 5.6)
问题描述
我使用邮递员添加用户或登录,用户添加成功但我收到此错误
I use postman to add user or to login , user has added with sucess but I get this error
"传递给 TymonJWTAuthJWT::fromUser() 的参数 1 必须是TymonJWTAuthContractsJWTSubject 的实例,AppUser 的实例给定,在 C:UsersWeb 中调用WorkStationDesktoplaravelappjwtlaravelvendor ymonjwt-authsrcJWTAuth.php第 54 行"
"Argument 1 passed to TymonJWTAuthJWT::fromUser() must be an instance of TymonJWTAuthContractsJWTSubject, instance of AppUser given, called in C:UsersWeb WorkStationDesktoplaravelappjwtlaravelvendor ymonjwt-authsrcJWTAuth.php on line 54"
我在这个 ligne 中找到了这个函数
and I found in this ligne this founction
public function attempt(array $credentials)
{
if (! $this->auth->byCredentials($credentials)) {
return false;
}
return $this->fromUser($this->user());
}
这是我的用户模型:
<?php
namespace App;
use TymonJWTAuthContractsJWTSubject;
use IlluminateNotificationsNotifiable;
use IlluminateFoundationAuthUser as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password','username','lastname','tel','tel',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function getJWTIdentifier()
{
return $this->getKey();
}
/**
* Return a key value array, containing any custom claims to be added to the JWT.
*
* @return array
*/
public function getJWTCustomClaims()
{
return [];
}
}
and this my register controller
<?php
namespace AppHttpControllers;
use AppHttpControllersController;
use IlluminateHttpRequest;
use AppUser;
use JWTFactory;
use JWTAuth;
use Validator;
use Response;
class APIRegisterController extends Controller
{
//
public function register( Request $request){
$validator = Validator::make($request -> all(),[
'email' => 'required|string|email|max:255|unique:users',
'username' =>'required',
'tel' => 'required',
'name' => 'required',
'lastname' => 'required',
'adress' => 'required',
'password'=> 'required'
]);
if ($validator -> fails()) {
# code...
return response()->json($validator->errors());
}
User::create([
'name' => $request->get('name'),
'email' => $request->get('email'),
'tel' => $request->get('tel'),
'username' => $request->get('username'),
'lastname' => $request->get('lastname'),
'adress' => $request->get('adress'),
'password'=> bcrypt($request->get('password'))
]);
$user = User::first();
$token = JWTAuth::fromUser($user);
return Response::json( compact('token'));
}
}
推荐答案
在你的 User 模型中实现 JWTSubject
:
Implement the JWTSubject
in your User model:
class User extends Authenticatable implements JWTSubject
这篇关于FatalThrowableError:参数 1 已通过 ..::fromUser() laravel 5.6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:FatalThrowableError:参数 1 已通过 ..::fromUser() laravel 5.6
基础教程推荐
- 在多维数组中查找最大值 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01