Laravel 电子邮件验证模板位置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52231870/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:02:11  来源:igfitidea点击:

Laravel Email Verification Template Location

laravellaravel-5.7

提问by Renzchler

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

我一直在阅读有关 laravel 电子邮件验证新功能的文档。在哪里可以找到发送给用户的电子邮件模板?它没有在这里显示:https: //laravel.com/docs/5.7/verification#after-verifying-emails

采纳答案by Sachin Aghera

Actually they not use any blade or template they create notification and write code for it in notification.

实际上,他们不使用任何刀片或模板,他们创建通知并在通知中为其编写代码。

回答by Илья Зеленько

Laravel uses this method of VerifyEmailnotification class for send email:

Laravel 使用VerifyEmail通知类的这个方法来发送电子邮件:

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

1)在app/Notifications/文件中创建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:

2)添加到用户模型:

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:authcommand 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.

make:auth执行命令时,laravel 将生成所有必要的电子邮件验证视图。此视图位于 resources/views/auth/verify.blade.php. 您可以根据应用程序的需要自由自定义此视图。

Source.

来源

回答by kotoFF

Also, if you want to translate standard mail VerifyEmail(or other where use Lang::fromJson(...)), you need create new json file in resources/lang/ and name it ru.json, for example. It may contain (resources/lang/ru.json) text below and must be valid.

此外,如果您想翻译标准邮件VerifyEmail(或其他使用 Lang::fromJson(...) 的地方),您需要在 resources/lang/ 中创建新的 json 文件并将其命名为 ru.json,例如。它可能包含下面的 (resources/lang/ru.json) 文本并且必须是有效的。

{
  "Verify Email Address" : "Подтверждение email адреса"
}

回答by scre_www

If a notification supports being sent as an email, you should define a toMail method on the notification class. This method will receive a $notifiable entity and should return a Illuminate\Notifications\Messages\MailMessage instance. Mail messages may contain lines of text as well as a "call to action".

如果通知支持作为电子邮件发送,您应该在通知类上定义一个 toMail 方法。此方法将接收一个 $notifiable 实体,并应返回一个 Illuminate\Notifications\Messages\MailMessage 实例。邮件消息可能包含文本行以及“号召性用语”。

/**
 * Get the mail representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return \Illuminate\Notifications\Messages\MailMessage
 */
public function toMail($notifiable)
{
    $url = url('/invoice/'.$this->invoice->id);

    return (new MailMessage)
                ->greeting('Hello!')
                ->line('One of your invoices has been paid!')
                ->action('View Invoice', $url)
                ->line('Thank you for using our application!');
}

You can use the laravel e-mail builder as documented here: https://laravel.com/docs/5.8/notifications#mail-notifications. Laravel will take care of the e-mail view.

您可以使用此处记录的 laravel 电子邮件生成器:https://laravel.com/docs/5.8/notifications#mail-notifications 。Laravel 会处理电子邮件视图。