Laravel: Reset Password From an API
Today, will share about how to reset your account in Laravel application from an API.
This is assumed you already setup JWT Auth in your Laravel app.
Create a new API controller –
php artisan make:controller Api/Auth/ForgotPasswordController and copy paste the following code, and add the forgot password route in
So, basically what I did was to use
IlluminateFoundationAuthSendsPasswordResetEmails trait, which being used in the default Laravel Forgot Password Controller.
I just copy codes from
sendResetLinkEmail method, and make changes on how the response we should receive from an API.
Then you are done! Easy right? 🙂
To test, open up your email, you just need to pass email address – just like we did in Laravel Auth Scaffold, then you are done.
The email owner will receive reset password link, and the owner open up the email, click on the link, go reset as usual, as we did on web app.
That’s all, thanks!
11 thoughts on “Laravel: Reset Password From an API”
It does not work man!!!!!!!!!
which part did not work?
Ya, good one buddy.
In the route action i had to add ‘Api\Auth’ before the ‘ForgotPasswordController’. Thanks!
i have erro like this “InvalidArgumentException thrown with message "Route [password.reset] not defined."”
When I try to use your code I get an error message that says “Route [password.reset] not defined.”
I know I have to add that route in api.php but I do not know which controller and which method I have to point to.
But once the user clicks on the password reset link there should be an form which accepts new passwords and an post api to save new password. Did you skip this part ??
Not really. If you’ve seen how Laravel handles the reset password issue, you’d realize that Laravel first shows you a form where you must enter your email address then, if the email address exists Laravel sends you an email with a link where the form where you can reset your password is.
Then in that second form you can reset your password, and at that time is when you can send your password you want to change.
Please help me in my postman it is showing 401 error I am new in laravel please guide me