How to extend or make a custom PasswordBroker sendResetLink() method in Laravel 10?

Posted by

In Laravel, the PasswordBroker class is responsible for handling password reset functionality. If you want to extend or customize the sendResetLink() method, you can follow these steps:

Step 1. Create a Custom PasswordBroker:

Make a new class that extends the PasswordBroker class in Illuminate\Auth\Passwords. You can accomplish this by adding a new PHP file, such as CustomPasswordBroker.php, to your project.

Step 2. Override the sendResetLink() Method:

Override the sendResetLink() method in your custom class. You can add your custom logic here.

Step 3. Register the Custom PasswordBroker:

In your AppServiceProvider or any service provider, bind your custom PasswordBroker implementation to Laravel’s service container.

Step 4. Update Configuration:

Update your config/auth.php file to use your custom PasswordBroker implementation.

You can choose to utilise the custom PasswordBroker you defined by adding the optional ‘use_custom_broker’ => true line.

At this point, Laravel ought to handle password reset functionality using your own PasswordBroker. The sendResetLink() function of your CustomPasswordBroker class allows you to implement custom logic.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x