When I used the passport package , I encountered this error
Call to a member function createToken() on null
Why do I get this error?
This is my code :
$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);
}
Auth::user()->createToken('MyApp')->accessToken
gives you problem? – Caskey$user
is null it meas that it probably guest (not logged). – Immortal$user = Auth::user();
and change$users
to $user` – Caskey