Laravel 5.3重新定义重置电子邮件刀片模板

Syl*_*Syl 17 laravel-5.3

如何在Laravel 5.3中自定义重置电子邮件刀片模板的路径?

使用的模板是: vendor/laravel/framework/src/Illuminate/Notifications/resources/views/email.blade.php

我想建立自己的.

此外,如何更改此预定义的电子邮件的文本: vendor/laravel/framework/src/Illuminate/Auth/Notifications/ResetPassword.php

public function toMail()
{
    return (new MailMessage)
        ->line([
            'You are receiving this email because we received a password reset request for your account.',
            'Click the button below to reset your password:',
        ])
        ->action('Reset Password', url('password/reset', $this->token))
        ->line('If you did not request a password reset, no further action is required.');
}
Run Code Online (Sandbox Code Playgroud)

小智 37

要更改模板,您应该使用artisan命令php artisan vendor:publish,它将在您的resources/views/vendor目录中创建刀片模板.要更改电子邮件的文本,您应该覆盖User模型上的sendPasswordResetNotification方法.这在重置电子邮件自定义部分中的https://laravel.com/docs/5.3/passwords中进行了描述.

您必须向User模型添加新方法.

public function sendPasswordResetNotification($token)
{
    $this->notify(new ResetPasswordNotification($token));
}
Run Code Online (Sandbox Code Playgroud)

并使用您自己的类来通知而不是ResetPasswordNotification.

更新:for @ lewis4u请求

分步说明:

  1. 要创建新的Notification类,必须使用此命令行php artisan make:notification MyResetPassword.它将在app/Notifications目录下创建一个新的Notification Class'MyResetPassword'.

  2. 添加use App\Notifications\MyResetPassword;到您的用户模型

  3. 为您的用户模型添加新方法.

    public function sendPasswordResetNotification($token)
    {
        $this->notify(new MyResetPassword($token));
    }
    
    Run Code Online (Sandbox Code Playgroud)
  4. 运行php artisan命令php artisan vendor:publish --tag=laravel-notifications运行此命令后,邮件通知模板将位于resources/views/vendor/notifications目录中.

  5. 如果您愿意,可以编辑您的MyResetPassword类方法toMail().它在这里描述https://laravel.com/docs/5.3/notifications

  6. 如果您愿意,请编辑您的电子邮件刀片模板.它的resources/views/vendor/notifications/email.blade.php

奖金: Laracast视频:https : //laracasts.com/series/whats-new-in-laravel-5-3/episodes/9

PS:谢谢@Garric15的建议 php artisan make:notification


Ban*_*rew 12

我想详细说明一个非常有用的欧根的答案,但没有足够的声誉来发表评论.

如果您想拥有自己的目录结构,则不必使用发布的Blade模板views/vendor/notifications/...当您创建新的Notification类并开始构建MailMessage类时,它有一个view()方法可用于覆盖默认视图:

/**
 * Get the mail representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return \Illuminate\Notifications\Messages\MailMessage
 */
public function toMail($notifiable)
{
    return (new MailMessage)
        ->view('emails.password_reset');
        // resources/views/emails/password_reset.blade.php will be used instead.
}
Run Code Online (Sandbox Code Playgroud)