Home > Web Development > Laravel Tutorials > Create a password reset page in Laravel 11.

Create a password reset page in Laravel 11.

Diego Cortés
Diego Cortés
January 20, 2025
Create a password reset page in Laravel 11.

In web development, password management is a crucial aspect of ensuring user security. Laravel, one of the most popular frameworks in PHP, makes this process easier. In this article, we will learn how to create a custom password reset page in Laravel 11, providing a better experience for your users.

Prerequisites

Before getting started, make sure you have Laravel 11 installed in your development environment. It is also advisable to have a basic understanding of PHP and the framework itself. To follow this tutorial, you will need the following tools:

  • Composer
  • A local web server (like XAMPP or Laravel Valet)
  • A code editor (such as Visual Studio Code)

Environment Setup

The first thing you should do is ensure that your project is correctly configured to send emails. Laravel offers a notification system that can be easily integrated with services like Mailgun, Amazon SES, or Gmail. Configure your .env file by adding the necessary information to connect with your email service.

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=your_username
MAIL_PASSWORD=your_password
MAIL_ENCRYPTION=null
[email protected]
MAIL_FROM_NAME="Your Name"

Creating the Logic for Password Reset

Laravel includes a ready-to-use password reset system. However, in this tutorial, we will customize it. Start by creating a controller that will handle the reset request. Use the Artisan command to generate a new controller:

php artisan make:controller Auth/ForgotPasswordController

In this controller, define methods to send the reset email and display the reset form. For example:

use Illuminate\Support\Facades\Password;

public function sendResetLink(Request $request)
{
    $request->validate(['email' => 'required|email']);

    $status = Password::sendResetLink($request->only('email'));

    return $status === Password::RESET_LINK_SENT
                ? back()->with(['status' => __($status)])
                : back()->withErrors(['email' => __($status)]);
}

This method will validate the email address and send a link for password reset.

Customizing the Views

Now that you have the logic to handle password reset, it's time to customize the views. Go to the resources/views/auth folder and modify the files related to password reset.

You can customize the password reset request form and the new password page, allowing you to style and structure them as desired to align with your website's design.

<form method="POST" action="{{ route('password.email') }}">
    @csrf
    <label for="email">Email</label>
    <input type="email" name="email" required>
    <button type="submit">Send Reset Link</button>
</form>

Testing the Functionality

Once you have everything set up, it's time to test it. Start your local server and navigate to the login page. From there, you should see a link or button that redirects you to the password reset page. Enter your email address and check if you receive the link correctly in your inbox.

Conclusion

Creating a password reset page in Laravel 11 not only improves user experience but also enhances the security of your application. By following the steps above, you can effectively implement this functionality and customize it to fit your site.

I invite everyone interested in web development to continue exploring more useful content on my blog, where you will find more news and tutorials about Laravel and other interesting topics.

Diego Cortés
Diego Cortés
Full Stack Developer, SEO Specialist with Expertise in Laravel & Vue.js and 3D Generalist

Categories

Page loaded in 22.47 ms