Creating Password Reset Function without using Laravel make:auth

旧城冷巷雨未停 提交于 2019-12-11 14:34:09

问题


I'm dealing with Laravel 5.6. I am using JWT Authentication, and I create my own authentication controller.

This is my recover method at 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.']
    ]);
}

In postman, if I execute the recover method, I get this message

{
    "success": false,
    "error": "Route [password.reset] not defined." 
}

How can I deal with this. thanks!


回答1:


You need to give the route a name, in this case password.reset. In your routes.php (or wherever you've defined them) call the name method:

Route::post('/password/reset', 'AuthController@recover')->name('password.reset');



回答2:


If you haven't run make:auth you don't have the route defined, as the error itself is saying.
Try to define the following route in routes/web.php

Route::post('/pwdreset', 'AuthController@recover')
    ->name('password.reset');


来源:https://stackoverflow.com/questions/48764888/creating-password-reset-function-without-using-laravel-makeauth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!