I'm using laravel and trying to make an Authenthication
with Laravel passport
. So I've done it by looking on the docs and youtube but I got this error. this is my AuthController
that I requested and the error.
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": "->"
},
.
.
.
}
I've searched it on google but I can't found anything that mention Trying to get property 'secret' of non-object
. I've tried php artisan passport:install
so I got the personal_access_clients
, but nothing's work.
NB
it's actually registered the user, but got this error response.