Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customizing password reset mail View in Laravel

Tags:

email

laravel

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 located?

like image 314
Asami Avatar asked May 28 '15 06:05

Asami


2 Answers

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

like image 159
Arno van Oordt Avatar answered Nov 15 '22 09:11

Arno van Oordt


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.
like image 36
Ali Malik Avatar answered Nov 15 '22 09:11

Ali Malik