Laravel Passport尝试获取非对象的属性“秘密”
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Laravel Passport尝试获取非对象的属性“秘密”相关的知识,希望对你有一定的参考价值。
我正在使用laravel并尝试使用Authenthication
制作一个Laravel passport
。因此,我通过查看文档和youtube完成了此操作,但出现此错误。这是我要求的AuthController
和错误。
AuthController.php
public function register(Request $request)
{
$validatedData = $request->validate([
'name'=>'required|max:55',
'email'=>'email|required|unique:users',
'password'=>'required|confirmed',
'who'=>'required'
]);
$validatedData['password'] = bcrypt($request->password);
$user = User::create($validatedData);
// Get access token
$accessToken = $user->createToken('authToken')->accessToken;
return response(['user' => $user, 'access_token' => $accessToken]);
}
ErrorsException
{
"message": "Trying to get property 'secret' of non-object",
"exception": "ErrorException",
"file": "C:\Panji\xampp\htdocs\papa\vendor\laravel\passport\src\PersonalAccessTokenFactory.php",
"line": 96,
"trace": [
{
"file": "C:\Panji\xampp\htdocs\papa\vendor\laravel\passport\src\PersonalAccessTokenFactory.php",
"line": 96,
"function": "handleError",
"class": "Illuminate\Foundation\Bootstrap\HandleExceptions",
"type": "->"
},
{
"file": "C:\Panji\xampp\htdocs\papa\vendor\laravel\passport\src\PersonalAccessTokenFactory.php",
"line": 71,
"function": "createRequest",
"class": "Laravel\Passport\PersonalAccessTokenFactory",
"type": "->"
},
{
"file": "C:\Panji\xampp\htdocs\papa\vendor\laravel\passport\src\HasApiTokens.php",
"line": 67,
"function": "make",
"class": "Laravel\Passport\PersonalAccessTokenFactory",
"type": "->"
},
{
"file": "C:\Panji\xampp\htdocs\papa\app\Http\Controllers\Api\AuthController.php",
"line": 26,
"function": "createToken",
"class": "App\User",
"type": "->"
},
{
"function": "register",
"class": "App\Http\Controllers\Api\AuthController",
"type": "->"
},
{
"file": "C:\Panji\xampp\htdocs\papa\vendor\laravel\framework\src\Illuminate\Routing\Controller.php",
"line": 54,
"function": "call_user_func_array"
},
{
"file": "C:\Panji\xampp\htdocs\papa\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php",
"line": 45,
"function": "callAction",
"class": "Illuminate\Routing\Controller",
"type": "->"
},
{
"file": "C:\Panji\xampp\htdocs\papa\vendor\laravel\framework\src\Illuminate\Routing\Route.php",
"line": 225,
"function": "dispatch",
"class": "Illuminate\Routing\ControllerDispatcher",
"type": "->"
},
.
.
.
}
我已经在Google上进行搜索,但是找不到任何提及Trying to get property 'secret' of non-object
的内容。我已经尝试过php artisan passport:install
,所以我得到了personal_access_clients
,但没有任何效果。
NB
它实际上已经注册了用户,但是收到了此错误响应。
答案
Passport中唯一使用该名称的属性的代码是映射到LaravelPassportClient
DB表的模型oauth_clients
,因此,我建议检查该表是否已创建并可供您的应用访问。
以上是关于Laravel Passport尝试获取非对象的属性“秘密”的主要内容,如果未能解决你的问题,请参考以下文章
尝试使用haversine公式在laravel中获取非对象的属性
laravel passport是否在承载令牌中序列化整个用户对象?
如何解决 laravel 数据表中的“尝试获取非对象的属性‘名称’”错误?
如何从 Laravel Passport 中的刷新令牌中获取 id?