Laravel implements password reset, while laravel implements password reset.
Introduction
Want to quickly implement this function? You only need to run it in the newly installed Laravel application.php artisan make:auth
(If you have run this command, ignore it), and then access the http://your-app.dev/register in your browser or other URLs assigned to the application, which generates everything the user needs to log on to registration, including password reset!
Most Web applications provide the password reset function for users, and Laravel is no exception. Laravel provides a convenient method for sending Password Reset links and implementing password reset logic, you do not need to implement it on your own in each application.
Note: before using the password reset function provided by Laravel, the User model must use Illuminate \ communications \ Notifiable trait.
Database Problems
Verify that the App/User model has been implementedIlluminate\Contracts\Auth\CanResetPassword
Contract. Of course, Laravel's App \ User model has implemented this interface and uses Illuminate \ Auth \ Passwords \ CanResetPassword trait to include the methods required to implement this interface.
Generate a reset token table for Migration
Next, the table used to store the password reset token must be created. Laravel has included the migration of this table, which is stored in the database/migrations directory. Therefore, all you have to do is run the Migration:
php artisan migrate
This table is password_resets:
Routing
Laravel comesAuth\ForgotPasswordController
AndAuth\ResetPasswordController
Controller (these two controller classes are automatically generated using the php artisan make: auth command), which is used to send Password Reset link emails and reset user passwords. The routes required to reset the password have been automatically generated using the make: auth command:
php artisan make:auth
The corresponding route is defined in the auth method of Illuminate \ Routing \ Router:
View
Like routing, view files required for password resetting are also generated using the make: auth command. These view files are located in
resources/views/auth/passwords
Directory, you can modify the generated files as needed.
Reset Password
After you have defined the route and view for resetting the user password, you only need to access the ingress route through/password/reset in the browser. Built-in frameworkForgotPasswordController
The logic for sending a password reset link email is included,ResetPasswordController
Contains the logic for resetting the user password:
Enter the registered email address, click the send Password Reset link, and the password reset link will be sent to the email address:
When you open your mailbox, you will receive the following Password Reset Email:
Click Reset Password To Go To The Reset Password page:
After entering the form and submitting it, You can reset the password.
After the password is reset, the user will automatically log on to the application and redirect to/home. You can customize the Redirect link after the password is reset by defining the redirectTo attribute of ResetPasswordController:
protected $redirectTo = '/dashboard';
Note: by default, the password reset token is valid for one hour. You can change the validity period by modifying the option expire in the config/auth. php file.
Custom
Custom authentication Guard
In the configuration file auth. in php, you can configure multiple "guards" for independent authentication based on multi-user tables, you can override the guard method on the built-in ResetPasswordController controller to use the guard you selected. This method will return a guard instance:
use Illuminate\Support\Facades\Auth;protected function guard(){ return Auth::guard('guard-name');}
Custom password broker
In the configuration file auth. in php, you can configure multiple passwords to reset the password broker of multiple user tables. Similarly, you can use the selected broker by rewriting the broker method in the ForgotPasswordController and ResetPasswordController controller:
Use Illuminate \ Support \ Facades \ Password;
/*** Obtain the broker used during password reset. ** @ return PasswordBroker * @ translator laravelacademy.org */protected function broker () {return Password: broker ('name ');}
Custom Password Reset email
You can easily edit the notification class that sends the password reset link to the User to implement custom Password Reset mail. To implement this function, you need to rewritesendPasswordResetNotification
Method. In this method, you can use any notification type you like to send a notification. The first parameter received by this method is password reset $ token:
/*** Send the password reset notification. ** @ param string $ token * @ return void */public function sendPasswordResetNotification ($ token) {$ this-> today y (new ResetPasswordNotification ($ token ));}
Summary
The above section describes Laravel's password reset function. I hope it will help you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!