Laravel: Reset Password From an API

By | April 27, 2018

Assalamualaikum,

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 routes/api.php.

So, basically what I did was to use Illuminate\Foundation\Auth\SendsPasswordResetEmails 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!

3 thoughts on “Laravel: Reset Password From an API

  1. Lucas'

    In the route action i had to add ‘Api\Auth’ before the ‘ForgotPasswordController’. Thanks!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

fifteen − 8 =