Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replace password reset mail template with custom template laravel 5.3

Tags:

I did the laravel command for authentication system , php artisan make:auth it made the authentication system for my app and almost everything is working.

Now when i use the forgot password and it sends me a token to my mail id , i see that the template contains laravel and some other things that i might wanna edit or ommit, to be precise , i want my custom template to be used there.

I looked up at the controllers and their source files but i can't find the template or the code that is displaying the html in the mail.

How do i do it ?

How do i change it?

This is the default template that comes from laravel to the mail. enter image description here

like image 330
Tilak Raj Avatar asked Dec 30 '16 17:12

Tilak Raj


People also ask

Where is the reset password email template laravel?

The email template will be inside resources/views/vendor/notifications folder.


1 Answers

Just a heads up: In addition to the previous answer, there are additional steps if you want to modify the notification lines like You are receiving this..., etc. Below is a step-by-step guide.

You'll need to override the default sendPasswordResetNotification method on your User model.

Why? Because the lines are pulled from Illuminate\Auth\Notifications\ResetPassword.php. Modifying it in the core will mean your changes are lost during an update of Laravel.

To do this, add the following to your your User model.

use App\Notifications\PasswordReset; // Or the location that you store your notifications (this is default).  /**  * Send the password reset notification.  *  * @param  string  $token  * @return void  */ public function sendPasswordResetNotification($token) {     $this->notify(new PasswordReset($token)); } 

Lastly, create that notification:

php artisan make:notification PasswordReset 

And example of this notification's content:

/**  * The password reset token.  *  * @var string  */ public $token;  /**  * Create a new notification instance.  *  * @return void  */ public function __construct($token) {     $this->token = $token; }  /**  * Get the notification's delivery channels.  *  * @param  mixed  $notifiable  * @return array  */ public function via($notifiable) {     return ['mail']; }  /**  * Build the mail representation of the notification.  *  * @param  mixed  $notifiable  * @return \Illuminate\Notifications\Messages\MailMessage  */ public function toMail($notifiable) {     return (new MailMessage)         ->line('You are receiving this email because we received a password reset request for your account.') // Here are the lines you can safely override         ->action('Reset Password', url('password/reset', $this->token))         ->line('If you did not request a password reset, no further action is required.'); } 
like image 75
camelCase Avatar answered Sep 28 '22 11:09

camelCase