8

我正在尝试更改subjectLaravel 5.7 随附的验证电子邮件中的默认字段。我如何以及在哪里更改它?我在网上和各地搜索过。因为它是全新的,我找不到答案。

4

3 回答 3

17

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

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

你可以在那里看到所有的字符串。

如果资源/lang 文件夹中还没有文件 en.json,请创建一个文件。

添加原始字符串和替换。例如

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

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

于 2018-09-19T22:40:34.583 回答
12

这是 MustVerifyEmail 特征

<?php

namespace Illuminate\Auth;

trait MustVerifyEmail
{
    /**
     * Determine if the user has verified their email address.
     *
     * @return bool
     */
    public function hasVerifiedEmail()
    {
        return ! is_null($this->email_verified_at);
    }

    /**
     * Mark the given user's email as verified.
     *
     * @return bool
     */
    public function markEmailAsVerified()
    {
        return $this->forceFill([
            'email_verified_at' => $this->freshTimestamp(),
        ])->save();
    }

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

如您所见,发送一个名为 VerifyEmail 的通知,所以我认为用您自己的通知覆盖用户模型上的此方法就足够了。您还应该检查此文件:vendor/laravel/framework/src/Illuminate/Auth/Notifications/VerifyEmail.php因为它包含通知并且可以用作自定义验证通知的示例。

User.php

    public function sendEmailVerificationNotification()
    {
        $this->notify(new MyNotification);
    }

然后运行

php artisan make:notification MyNotification

在您的通知中,您可以扩展到Illuminate\Auth\Notifications\VerifyEmail

然后你可以覆盖通知 toMail 功能......没有尝试过,但这应该可以。

于 2018-09-19T14:33:49.007 回答
0

你可以在你邮寄的地方发布你的功能吗?我用:

\Mail::to($user)->subject('Your Subject')->bcc([$reports,$me])->send(new Declined($user));

即:向 $user 发送邮件,设置主题,盲送,然后在传递用户的同时发送邮件。这也适用于降价邮件。您使用->操作员添加邮件的所有附加内容,因此您可以添加密件抄送(就像我所做的那样)以及抄送等。

于 2018-09-19T14:49:17.857 回答