更改Laravel 5.7中验证电子邮件的默认“主题"字段 [英] Changing the default “Subject” field for verification emails in Laravel 5.7

查看:174
本文介绍了更改Laravel 5.7中验证电子邮件的默认“主题"字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改Laravel 5.7随附的验证电子邮件中的默认subject字段.我如何以及在哪里进行更改?我已经搜索了整个地方和在线.因为它是全新的,所以找不到答案.

I'm trying to change the default subject field in the verification email that comes with Laravel 5.7. How and where do I change it? I have searched all over the place and online. Because it's brand new I can't find an answer.

推荐答案

您无需编写任何代码.该通知将所有字符串包装在Lang类中,因此您可以提供从英语到另一种语言的翻译字符串,如果您只是想更改措辞,甚至可以提供英语到英语的翻译字符串.

You don't need to code anything. The notification has all the strings wrapped in the Lang class so that you can provide translation strings from english to another language, or even english to english if you just want to change the wording.

查看/vendor/laravel/framework/src/Illuminate/Auth/Notifications/VerifyEmail.php

Look in /vendor/laravel/framework/src/Illuminate/Auth/Notifications/VerifyEmail.php

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.'));
}

您可以在此处看到所有字符串.

You can see all the strings there.

如果您在resources/lang文件夹上还没有一个文件,请创建一个文件en.json.

Create a file en.json if you don't have one on the resources/lang folder already.

添加原始字符串并替换. 例如

add the original string and the replacement. eg

{
    "Verify Email Address": "My preferred subject",
    "Please click the button below to verify your email address.":"Another translation"
}

要翻译成另一种语言,请在config/app.php中更改语言环境,并使用locale.json创建翻译文件

To translate to another language, change the locale in config/app.php and create a translation file with the locale.json

这篇关于更改Laravel 5.7中验证电子邮件的默认“主题"字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆