Customizing password reset mail View in Laravel

前端 未结 2 1816
清歌不尽
清歌不尽 2021-01-02 16:48

How can I change what appears in the password reset email in laravel? Like addressing the user with his name and show the password reset link etc. Where is that email view l

相关标签:
2条回答
  • 2021-01-02 17:19

    In Laravel 5.3 they changed the entire password reset code, so the given answer doesn't work anymore.

    If you want to change the basic texts you should copy vendor/laravel/framework/src/Illuminate/Auth/Notifications/ResetPassword.php to some place in your own app (e.g. app/Notifications/ResetPassword.php), set the correct namespace and alter the texts as you wish. (don't alter the original ResetPassword.php since it's bad practice to alter files in the vendor folder!)

    Then add a sendPasswordResetNotification method to the User class and make sure to reference to the appropriate ResetPassword class:

    use App\Notifications\ResetPassword;
    
    ...
    
    public function sendPasswordResetNotification($token) {
        $this->notify(new ResetPassword($token));
    }
    

    If you want to change the rest of the mail template (which is used for all other mails as well) do the following:

    Run php artisan vendor:publish

    This will copy some blades from the vendor folder to the resources/views/vendor The resources/views/vendor/notifications/email.blade.php is the one you want to change.

    Hope this helps for people who got stuck in Laravel 5.3

    0 讨论(0)
  • 2021-01-02 17:34

    Yes you can change the email template, which is located at

     resources/views/emails/password.blade.php.
    

    For customization pass an instance of User model to this view and echo out user name there like:

    Hello, {{$user->username}}
    //And Body of Reset link goes here
    

    Update for laravel 5.3+

    In updated laravel versions the code structure is revamped. Password reset mail is now at vendor/laravel/framework/src/Illuminate/Auth/Notifications/ResetPassword.php

    and its corresponding template is at: resources/views/vendor/notifications/email.blade.php

    So in order to customize it, you may need to:

    • Copy it to somewhere in your app's directory.
    • Set the proper namespace to refer to it.
    • Add a new method to User class & reference it to newly copied class
    • Customize.
    0 讨论(0)
提交回复
热议问题