我正在处理Laravel 5.6。我正在使用JWT身份验证,我创建了自己的身份验证控制器。
这是我在AuthController上的恢复方法,
public function recover(Request $request)
{
$user = User::where('email', $request->email)->first();
if (!$user) {
$error_message = "Your email address was not found.";
return response()->json(['success' => false, 'error' => ['email'=> $error_message]], 401);
}
try {
Password::sendResetLink($request->only('email'), function (Message $message) {
$message->subject('Your Password Reset Link');
});
} catch (\Exception $e) {
$error_message = $e->getMessage();
return response()->json(['success' => false, 'error' => $error_message], 401);
}
return response()->json([
'success' => true, 'data'=> ['message'=> 'A reset email has been sent! Please check your email.']
]);
}
在postman中,如果我执行recover方法,我会收到此消息
{
"success": false,
"error": "Route [password.reset] not defined."
}
我该如何处理这件事。谢谢!
答案 0 :(得分:1)
您需要为路线命名,在本例中为password.reset
。在routes.php
(或您定义的任何地方)中,调用name
方法:
Route::post('/password/reset', 'AuthController@recover')->name('password.reset');
答案 1 :(得分:0)
如果你没有运行make:auth
,你就没有定义路线,正如错误本身所说的那样
尝试在routes/web.php
Route::post('/pwdreset', 'AuthController@recover')
->name('password.reset');