PasswordResetController with methods for showing the reset request form, sending the reset email, showing the reset form, and updating the passwordPassword reset in Laravel - Mini Project: Build & Apply
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.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.
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.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.
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.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.
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.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.
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
