Nasrul Hazim Bin Mohamad

Laravel: Reset Password From an API

Apr
27

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!

Reset Your Password from API

Jan
05

UPDATE 27/4/2018 – New blog post about reset password from an API – LARAVEL: RESET PASSWORD FROM AN API. Much more simpler than this one.

As you may know, Laravel provide a scaffold auth, which include reset/forgot password on web applications side. But what if you have a mobile application that need to reset password from the mobile application?

In this post, I’ll show you how to reset user’s password from an API in Laravel.

UPDATE 02/07/2017:

In case you’re looking for App\Transformers\Json, you basically can create a class called Json in app/Transformers directory.

In the Json class:

<?php

namespace App\Transformers;

class Json
{
    public static function response($data = null, $message = null)
    {
        return [
            'data'    => $data,
            'message' => $message,
        ];
    }
}

Please make sure to composer dumpautoload -o afterward.

UPDATE 27/4/2018 – New blog post about reset password from an API – LARAVEL: RESET PASSWORD FROM AN API. Much more simpler than this one.