Laravel 5.4 ^-如何自定义通知电子邮件的布局? [英] Laravel 5.4^ - How to customize notification email layout?

查看:156
本文介绍了Laravel 5.4 ^-如何自定义通知电子邮件的布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自定义通过电子邮件发送通知时使用的HTML电子邮件布局.

I am trying to customize the HTML email layout that is used when sending notifications via email.

我已经发布了邮件视图和通知视图.

I have published both the mail and notification views.

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

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

如果修改/resources/views/vendor/notifications/email.blade.php文件,则只能更改所发送电子邮件的正文内容.我还希望修改电子邮件布局的页脚,标题和其他所有部分.

If I modify the /resources/views/vendor/notifications/email.blade.php file, I can only change the BODY content of the emails that get sent. I am looking to modify the footer, header, and every other part of the email layout as well.

我也尝试过修改/resources/vendor/mail/html/内部的视图,但是每当发送通知时,它甚至都不会使用这些视图,而是使用默认的laravel框架视图.

I tried also modifying the views inside /resources/vendor/mail/html/, but whenever the notification gets sent, it is not even using these views and instead uses the default laravel framework ones.

我知道我可以在Notification类返回的MailMessage上设置一个视图,但是我想保留标准的line()greeting()等功能.

I am aware I can set a view on the MailMessage returned by my Notification class, but I want to keep the standard line(), greeting(), etc. functions.

有人知道如何使用/resources/vendor/mail/html中的视图获取通知以发送电子邮件吗?

Does anyone know how I can get my notifications to send email using the views in /resources/vendor/mail/html ?

以下是我的/resources/views/vendor/notifications/email.blade.php文件,但没有自定义页眉/页脚/总体布局的地方.

The following is my /resources/views/vendor/notifications/email.blade.php file, but it does not have anywhere to customize the header/footer/ overall layout.

@component('mail::message')
{{-- Greeting --}}
@if (! empty($greeting))
# {{ $greeting }}
@else
@if ($level == 'error')
# Whoops!
@else
# Hello!
@endif
@endif

{{-- Intro Lines --}}
@foreach ($introLines as $line)
{{ $line }}

@endforeach

{{-- Action Button --}}
@if (isset($actionText))
<?php
    switch ($level) {
        case 'success':
            $color = 'green';
            break;
        case 'error':
            $color = 'red';
            break;
        default:
            $color = 'blue';
    }
?>
@component('mail::button', ['url' => $actionUrl, 'color' => $color])
{{ $actionText }}
@endcomponent
@endif

{{-- Outro Lines --}}
@foreach ($outroLines as $line)
{{ $line }}

@endforeach

<!-- Salutation -->
@if (! empty($salutation))
{{ $salutation }}
@else
Regards,<br>{{ config('app.name') }}
@endif

<!-- Subcopy -->
@if (isset($actionText))
@component('mail::subcopy')
If you’re having trouble clicking the "{{ $actionText }}" button, copy and paste the URL below
into your web browser: [{{ $actionUrl }}]({{ $actionUrl }})
@endcomponent
@endif
@endcomponent

推荐答案

运行此命令

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

laravel 5.7+更新

update for laravel 5.7+

php artisan vendor:publish

然后您将得到:

  [<number>] Tag: laravel-mail
  [<number>] Tag: laravel-notifications

,然后在前面键入该数字即可发布文件进行编辑

and then just type in that number in front to publish the file for editing

然后在

/resources/views/vendor/mail/html/

您可以编辑所有组件并自定义所需的任何内容. 例如,我已经编辑了句子保留所有权利".转到该文件中该图像底部的所有测试保留":

you can edit all the components and customize anything you want. For example i have edited the sentence "All rights reserved". to "All test reserved" at the bottom of that image inside this file:

/resources/views/vendor/mail/html/message.blade.php

这就是我得到的:

这篇关于Laravel 5.4 ^-如何自定义通知电子邮件的布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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