Refer to the ForgotPasswordController and ResetPasswordController files in the Auth folder.
For convenience, we directly copy these two files first:
Paste into the Api folder:
Modify the namespace of the two class files to:
namespace App\Http\Controllers\Api;
When we forget the password, the main thing we need is the sendResetLinkEmail method in the SendsPasswordResetEmails trait.
So we add a route in api.php to direct the reset request to this method;
Route::post('/password/email', 'Api\ForgotPasswordController@sendResetLinkEmail');
For the same password reset request, the reset method in the trait ResetsPasswords is needed.
So we add a route in api.php to direct the reset request to this method;
Route::post('/password/reset', 'Api\ResetPasswordController@reset');
Note: If you need to rewrite the methods in the two traits, for example, our api request needs a json to return {Laravel 7.x version already supports judgment to return json result}, you can use Ctrl + o in ForgotPasswordController and ResetPasswordController respectively Shortcut keys can be rewritten.