0
0
Laravelframework~30 mins

Password reset in Laravel - Mini Project: Build & Apply

Choose your learning style9 modes available
Password reset
📖 Scenario: You are building a simple Laravel app that allows users to reset their password if they forget it. This is a common feature in many websites to help users regain access securely.
🎯 Goal: Create the basic password reset flow in Laravel by setting up the necessary routes, controller methods, and views to send a reset link and update the password.
📋 What You'll Learn
Create a route group for password reset with named routes
Create a controller named PasswordResetController with methods for showing the reset request form, sending the reset email, showing the reset form, and updating the password
Use Laravel's built-in password broker to send reset links and reset passwords
Create simple Blade views for the reset request form and the password reset form
💡 Why This Matters
🌍 Real World
Password reset is a critical feature in almost all web applications to help users regain access when they forget their password.
💼 Career
Understanding how to implement password reset flows using Laravel's built-in features is a common task for backend and full-stack developers working with Laravel.
Progress0 / 4 steps
1
Set up password reset routes
In the routes/web.php file, create a route group with prefix password and name prefix password.. Inside it, add these routes: a GET route /reset named request that uses PasswordResetController@showRequestForm, a POST route /email named email that uses PasswordResetController@sendResetLinkEmail, a GET route /reset/{token} named reset that uses PasswordResetController@showResetForm, and a POST route /reset named update that uses PasswordResetController@reset.
Laravel
Need a hint?

Use Laravel's Route facade to create a group with prefix password and name prefix password.. Then add the four routes with the exact methods and names.

2
Create PasswordResetController with request form methods
Create a controller named PasswordResetController in app/Http/Controllers. Add a public method showRequestForm that returns the view auth.passwords.email. Add a public method sendResetLinkEmail that accepts a Request $request, validates the email field as required and email format, and uses Password::sendResetLink to send the reset link. Return back with status or error message.
Laravel
Need a hint?

Define the controller class with the two methods. Use view('auth.passwords.email') to show the form. Use $request->validate and Password::sendResetLink to send the email.

3
Add reset form methods in PasswordResetController
In PasswordResetController, add a public method showResetForm that accepts $token and returns the view auth.passwords.reset passing the token and email from the request. Add a public method reset that accepts Request $request, validates token, email, password (required, confirmed, min 8), and uses Password::reset to update the password. Return redirect to login with success or back with errors.
Laravel
Need a hint?

Add the two methods to show the reset form and handle the reset. Use view('auth.passwords.reset') with token and email. Validate inputs and use Password::reset with a callback to update the password.

4
Create Blade views for password reset forms
Create two Blade view files: resources/views/auth/passwords/email.blade.php and resources/views/auth/passwords/reset.blade.php. In email.blade.php, create a form with method POST to route password.email containing an email input named email and a submit button labeled 'Send Password Reset Link'. In reset.blade.php, create a form with method POST to route password.update containing hidden input token, email input email, password input password, password confirmation input password_confirmation, and a submit button labeled 'Reset Password'. Include CSRF tokens in both forms.
Laravel
Need a hint?

Create two Blade files with forms for requesting a reset link and for resetting the password. Use POST method, include CSRF tokens, and the exact input names and labels.