Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Email Verification Template Location

I have been reading from the documentation about the new feature of laravel the email verification. Where can I locate the email template that is sent to the user? It does not show here: https://laravel.com/docs/5.7/verification#after-verifying-emails

like image 253
Renzchler Avatar asked Sep 08 '18 03:09

Renzchler


People also ask

How does laravel verify email address?

First, a route will be needed to display a notice to the user that they should click the email verification link in the verification email that Laravel sent them after registration. Second, a route will be needed to handle requests generated when the user clicks the email verification link in the email.


2 Answers

Laravel uses this method of VerifyEmail notification class for send email:

public function toMail($notifiable)
{
    if (static::$toMailCallback) {
        return call_user_func(static::$toMailCallback, $notifiable);
    }
    return (new MailMessage)
        ->subject(Lang::getFromJson('Verify Email Address'))
        ->line(Lang::getFromJson('Please click the button below to verify your email address.'))
        ->action(
            Lang::getFromJson('Verify Email Address'),
            $this->verificationUrl($notifiable)
        )
        ->line(Lang::getFromJson('If you did not create an account, no further action is required.'));
}

Method in source code.

If you wanna use your own Email template, you can extend Base Notification Class.

1) Create in app/Notifications/ file VerifyEmail.php

<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\Lang;
use Illuminate\Auth\Notifications\VerifyEmail as VerifyEmailBase;

class VerifyEmail extends VerifyEmailBase
{
//    use Queueable;

    // change as you want
    public function toMail($notifiable)
    {
        if (static::$toMailCallback) {
            return call_user_func(static::$toMailCallback, $notifiable);
        }
        return (new MailMessage)
            ->subject(Lang::getFromJson('Verify Email Address'))
            ->line(Lang::getFromJson('Please click the button below to verify your email address.'))
            ->action(
                Lang::getFromJson('Verify Email Address'),
                $this->verificationUrl($notifiable)
            )
            ->line(Lang::getFromJson('If you did not create an account, no further action is required.'));
    }
}

2) Add to User model:

use App\Notifications\VerifyEmail;

and

/**
 * Send the email verification notification.
 *
 * @return void
 */
public function sendEmailVerificationNotification()
{
    $this->notify(new VerifyEmail); // my notification
}

Also if you need blade template:

laravel will generate all of the necessary email verification views when the make:auth command is executed. This view is placed in resources/views/auth/verify.blade.php. You are free to customize this view as needed for your application.

Source.

like image 195
Илья Зеленько Avatar answered Sep 20 '22 15:09

Илья Зеленько


Answer in comment already. Sent by the toMail() method.

vendor\laravel\framework\src\Illuminate\Auth\Notifications\VerifyEmail::toMail();

For template structure and appearance; take a look at this locations also and you can also publish to modify the template:

\vendor\laravel\framework\src\Illuminate\Notifications\resources\views\email.blade.php
\vendor\laravel\framework\src\Illuminate\Mail\resources\views\

To publish those locations:

php artisan vendor:publish --tag=laravel-notifications
php artisan vendor:publish --tag=laravel-mail

After running this command, the mail notification templates will be located in the resources/views/vendor directory.

Colors and style are controlled by the CSS file in resources/views/vendor/mail/html/themes/default.css

like image 35
DAVID AJAYI Avatar answered Sep 20 '22 15:09

DAVID AJAYI