在用户通过api注册后,我尝试验证电子邮件,我能够将验证码发送到我在mailtrap中有响应的电子邮件,现在,当我单击“验证电子邮件”按钮时,出现此错误在null上调用成员函数getKey() 这是我的代码
public function verify(Request $request)
{
if (! hash_equals((string) $request->route('id'), (string) $request->user()->getKey())) {
throw new AuthorizationException;
}
if (! hash_equals((string) $request->route('hash'), sha1($request->user()->getEmailForVerification()))) {
throw new AuthorizationException;
}
if ($request->user()->hasVerifiedEmail()) {
return $request->wantsJson()
? new Response(['message' => 'Already Verified'], 204)
: redirect($this->redirectPath());
}
if ($request->user()->markEmailAsVerified()) {
event(new Verified($request->user()));
}
if ($response = $this->verified($request)) {
return $response;
}
return $request->wantsJson()
? new Response(['message' => 'Successfully Verified'], 204)
: redirect($this->redirectPath())->with('verified', true);
}
这是路线
Route::get('/email/verify/{id}/{hash}', 'Api\VerificationController@verify')->name('verification.verify');
由于前端尚未准备就绪,我正在使用邮递员来测试API
这是发送到邮件陷阱的链接
答案 0 :(得分:0)
如果这是经过身份验证的用户,则可以尝试使用Auth::user()
代替$request->user()
答案 1 :(得分:0)
也许现在回答为时已晚,但我遇到了同样的问题,唯一为我解决了这个问题的是:
use App\Model\User;
然后在这个“验证”方法中
$user = User::findOrFail($request->route("id"));
最后,用这个 $user 替换 $request()->user,