Password reset helps users get a new password if they forget the old one. It keeps accounts safe and easy to access again.
Password reset in Laravel
php artisan ui vue --auth // Use built-in Laravel routes and controllers for password reset // Routes in routes/web.php Route::get('password/reset', [ForgotPasswordController::class, 'showLinkRequestForm'])->name('password.request'); Route::post('password/email', [ForgotPasswordController::class, 'sendResetLinkEmail'])->name('password.email'); Route::get('password/reset/{token}', [ResetPasswordController::class, 'showResetForm'])->name('password.reset'); Route::post('password/reset', [ResetPasswordController::class, 'reset'])->name('password.update');
Laravel provides built-in controllers and views for password reset.
You can customize email templates and views if needed.
// Show form to request password reset link Route::get('password/reset', [ForgotPasswordController::class, 'showLinkRequestForm'])->name('password.request');
// Send password reset email Route::post('password/email', [ForgotPasswordController::class, 'sendResetLinkEmail'])->name('password.email');
// Show form to reset password using token Route::get('password/reset/{token}', [ResetPasswordController::class, 'showResetForm'])->name('password.reset');
// Update password in database Route::post('password/reset', [ResetPasswordController::class, 'reset'])->name('password.update');
This example shows a simple controller to display the password reset request form and send the reset email. The routes connect to these controller methods.
<?php namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; use Illuminate\Http\Request; use Illuminate\Support\Facades\Password; class ForgotPasswordController extends Controller { public function showLinkRequestForm() { return view('auth.passwords.email'); } public function sendResetLinkEmail(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)]); } } // In routes/web.php use App\Http\Controllers\Auth\ForgotPasswordController; Route::get('password/reset', [ForgotPasswordController::class, 'showLinkRequestForm'])->name('password.request'); Route::post('password/email', [ForgotPasswordController::class, 'sendResetLinkEmail'])->name('password.email');
Make sure your mail settings in .env are configured to send emails.
Laravel stores reset tokens securely and expires them after a set time.
You can customize views in resources/views/auth/passwords/ for branding.
Password reset lets users recover access safely.
Laravel has built-in routes and controllers to handle this easily.
Always validate user input and configure email sending properly.
Practice
Solution
Step 1: Understand password reset functionality
Password reset is designed to help users regain access if they forget their password.Step 2: Identify the correct purpose in options
Only To allow users to safely recover access to their accounts describes recovering account access safely, which matches password reset.Final Answer:
To allow users to safely recover access to their accounts -> Option DQuick Check:
Password reset = recover access [OK]
- Confusing password reset with profile updates
- Thinking it deletes the account
- Assuming it changes email address
Solution
Step 1: Identify command to publish email templates
Laravel uses vendor:publish with specific tags to publish resources like email templates.Step 2: Match the correct tag for mail templates
The tag 'laravel-mail' is used to publish mail templates including password reset emails.Final Answer:
php artisan vendor:publish --tag=laravel-mail -> Option CQuick Check:
Publish mail templates = vendor:publish --tag=laravel-mail [OK]
- Using make:auth which is deprecated
- Wrong tag like laravel-password-reset
- Running migrate instead of publishing
<form action="{{ route('password.update') }}" method="?">
@csrf
<input type="hidden" name="token" value="{{ $token }}">
<input type="email" name="email" required>
<input type="password" name="password" required>
<input type="password" name="password_confirmation" required>
<button type="submit">Reset Password</button>
</form>Solution
Step 1: Understand password reset form submission
The form sends sensitive data (password, token) to update the password securely.Step 2: Identify correct HTTP method for secure data submission
POST method is used to send data to the server for processing, especially for updates like password reset.Final Answer:
POST -> Option BQuick Check:
Form sending data securely = POST [OK]
- Using GET which exposes data in URL
- Using PUT or DELETE which are not default form methods
- Omitting CSRF token with POST
use Illuminate\Support\Facades\Password; Password::sendResetLink(['email' => $request->email]);
What is the likely mistake?
Solution
Step 1: Understand Password::sendResetLink usage
This method returns a status indicating if the email was sent successfully or failed.Step 2: Identify missing check for success
Without capturing and checking the return value, you won't know if sending failed silently.Final Answer:
Missing the return statement to check success -> Option AQuick Check:
Check sendResetLink return to confirm email sent [OK]
- Assuming Mail facade is needed directly
- Skipping email validation before sending
- Trying to call notify() manually for reset link
Solution
Step 1: Identify where password reset token expiry is configured
Laravel stores password reset settings in config/auth.php under 'passwords' array.Step 2: Locate the 'expire' key for users password broker
The 'expire' key defines token validity in minutes; changing it to 30 sets expiry to 30 minutes.Final Answer:
config/auth.php, 'passwords.users.expire' => 30 -> Option AQuick Check:
Token expiry set in config/auth.php passwords.users.expire [OK]
- Trying to set expiry in mail config
- Adding middleware instead of config change
- Modifying controller instead of config
Ready to prove it?
Pass the test and this pattern moves unknown
