我用passport包的时候遇到这个错误
在 null 上调用成员函数 createToken()
为什么我会收到这个错误?
这是我的代码:
$users = Users::where('Email' , $username)
->where( 'Password' , $password)
->where('UserStatus' , config('global.active'))
->first();
if($users) {
$success['token'] = $users->createToken('MyApp')->accessToken;
return response()->json(['success' => $success], $this->successStatus);
} else {
return response()->json(['error'=>'Unauthorised'], 401);
}
Run Code Online (Sandbox Code Playgroud) 当我使用护照包时,这样做后,
$success['token'] = $users->createToken('MyApp')->accessToken;
Run Code Online (Sandbox Code Playgroud)
我将处理此代码中的错误:
protected function createRequest($client, $userId, array $scopes)
{
return (new ServerRequest)->withParsedBody([
'grant_type' => 'personal_access',
'client_id' => $client->id,
'client_secret' => $client->secret,
'user_id' => $userId,
'scope' => implode(' ', $scopes),
]);
}
Run Code Online (Sandbox Code Playgroud)
错误文本:
Trying to get property 'id' of non-object
Run Code Online (Sandbox Code Playgroud)
为什么 clinet variabale 为 null ?
我想在Laravel的框架中为我的整个项目创建一个全局变量,所以我如何在一个类中创建它并在任何地方创建它.有人可以指导吗?