Laravel

Customize Laravel 5.6 Default Password Reset Email Template

Replace Default Reset Password Email Template in Laravel 5.6


Recently I received a request from one of my follower on techalyst.com, he was interested to know How to Override the default password reset email template on Laravel 5.6,
So in this post, i will show you how to override the default behavior of laravel, so that It will accept a custom email template view for sending password reset email to users.

Create file Notifications/ResetPasswordNotification.php

<?php

namespace App\Notifications;

use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Notifications\Messages\MailMessage;

class ResetPasswordNotification extends ResetPassword
{
    /**
     * Build the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        if (static::$toMailCallback) {
            return call_user_func(static::$toMailCallback, $notifiable, $this->token);
        }

        return (new MailMessage)
            ->view(
                'auth.emails.password', ['token' => $this->token]
            )
            ->subject(Lang::getFromJson('Reset Password Notification'));
    }
}

Edit App/User.php add at the top

use App\Notifications\ResetPasswordNotification;

and add the following method

    /**
     * Send the password reset notification.
     * @note: This override Authenticatable methodology
     *
     * @param  string  $token
     * @return void
     */
    public function sendPasswordResetNotification($token)
    {
        $this->notify(new ResetPasswordNotification($token));
    }

that is all, now go ahead and create your password reset email template in your Laravel 5.6 project view folder : 

auth.emails.password

if you have any questions regarding "Overriding Laravel 5.6 Default Password Reset Email Template", please feel free to leave your comment bellow.


Share your thoughts

You may use <pre> </pre> tag for writing multi lines code or <code> </code> tag for writing single line code in the comment section bellow.