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.

Written by Akram Wahid 1 year ago

are you looking for a chief cook who can well craft laravel and vuejs, to make some awsome butterscotch,
yes then it is right time for you to look at my profile.

Do you want to write Response or Comment?

You must be a member of techalyst to proceed!

Continue with your Email ? Sign up / log in

Responses

Be the first one to write a response :(

{{ item.member.name }} - {{ item.created_at_human_readable }}

{{ reply.member.name }} - {{ reply.created_at_human_readable }}