Laravel通知想要在通知刀片模板中使用视图html

Shi*_*iro 5 laravel laravel-notification laravel-5.7

我正在使用 Laravel 版本 5.7.20 构建自定义 Markdown 模板。/resources/views/vendor/notifications/email.blade.php 发出命令后生成的模板被复制php artisan vendor:publish --tag=laravel-notifications

显示 HTML 的以下作品:

return (new MailMessage)
    ->line(new HtmlString('The <strong>introduction</strong> to the notification.'))
    ->line('The <strong>introduction</strong> to the notification.')
    ->line(new HtmlString('Due Date: <strong>' . Carbon::parse($this->info->created_at)->format('Y-m-d H:i') . '</strong>'))
    ->line('Due Date: <strong>' . Carbon::parse($this->info->created_at)->format('Y-m-d H:i') . '</strong>')
    ->action('Notification Action', url('/'));
Run Code Online (Sandbox Code Playgroud)

图像

这是行不通的。这是使用我自己的降价

return (new MailMessage)
            ->line(new HtmlString('The <strong>introduction</strong> to the notification.'))
            ->line('The <strong>introduction</strong> to the notification.')
            ->line(new HtmlString('Due Date: <strong>' . Carbon::parse($this->info->created_at)->format('Y-m-d H:i').'</strong>'))
            ->line('Due Date: <strong>' . Carbon::parse($this->info->created_at)->format('Y-m-d H:i').'</strong>')
            ->action('Notification Action', url('/'))
            ->markdown('mail.notification.permission');
Run Code Online (Sandbox Code Playgroud)

图像

我的 mail.notification.permission 文件完全复制自laravel-project/resources/views/vendor/notifications/email.blade.php

我想我需要查看而不是降价。但我改变了,->view('mail.notification.permission');我得到了错误No hint path defined for [mail]. (View: /Users/shiro/Sites/laravel-project/resources/views/mail/notification/permission.blade.php)

我应该使用 html(而不是标记格式)复制哪个文件。

我在通知使用 ->view 而不是 ->markdown 中没有看到任何解决方案。或者在通知电子邮件中显示 html 的正确流程是什么?

Shi*_*iro 6

好的,我发现了错误。

\n\n

如果要使用->view(),刀片模板不能使用@component(\'mail::message\'),它必须使用新的刀片布局构建(像普通页面一样构建您自己的视图)。那么你就不会得到No hint path defined for [mail]错误。

\n\n

Laravel 通知标记很多以学习它们的语法和生态系统。对于那些想要简单通知的人来说这非常有用。但如果您想要自定义页面,我建议使用view().

\n\n

我分享我的布局刀片文件,该文件是我从 mark down 发出后复制的。内容部分你有自己的逻辑。

\n\n
    public function toMail($notifiable)\n    {\n        return (new MailMessage)\n            ->subject(\'New Invoice\')\n            ->view( \'mail.notification.custom_invoice\', [\'invoice\' => $this->invoice]);\n    {\n
Run Code Online (Sandbox Code Playgroud)\n\n

email_layout.blade.php

\n\n
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml">\n<head>\n    <meta name="viewport" content="width=device-width, initial-scale=1.0">\n    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">\n</head>\n<body style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; background-color: #f5f8fa; color: #74787E; height: 100%; hyphens: auto; line-height: 1.4; margin: 0; -moz-hyphens: auto; -ms-word-break: break-all; width: 100% !important; -webkit-hyphens: auto; -webkit-text-size-adjust: none; word-break: break-word;">\n<style>\n    @media  only screen and (max-width: 600px) {\n        .inner-body {\n            width: 100% !important;\n        }\n\n        .footer {\n            width: 100% !important;\n        }\n    }\n\n    @media  only screen and (max-width: 500px) {\n        .button {\n            width: 100% !important;\n        }\n    }\n</style>\n\n<table class="wrapper" width="100%" cellpadding="0" cellspacing="0" style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; background-color: #f5f8fa; margin: 0; padding: 0; width: 100%; -premailer-cellpadding: 0; -premailer-cellspacing: 0; -premailer-width: 100%;">\n    <tr>\n        <td align="center" style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box;">\n            <table class="content" width="100%" cellpadding="0" cellspacing="0" style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; margin: 0; padding: 0; width: 100%; -premailer-cellpadding: 0; -premailer-cellspacing: 0; -premailer-width: 100%;">\n                <tr>\n                    <td class="header" style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; padding: 25px 0; text-align: center;">\n                        <a href="{{ url(\'/\') }}" style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; color: #bbbfc3; font-size: 19px; font-weight: bold; text-decoration: none; text-shadow: 0 1px 0 white;">\n                            {{ config(\'app.name\', \'Laravel\') }}\n                        </a>\n                    </td>\n                </tr>\n\n\n                <!-- Email Body -->\n                <tr>\n                    <td class="body" width="100%" cellpadding="0" cellspacing="0" style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; background-color: #FFFFFF; border-bottom: 1px solid #EDEFF2; border-top: 1px solid #EDEFF2; margin: 0; padding: 0; width: 100%; -premailer-cellpadding: 0; -premailer-cellspacing: 0; -premailer-width: 100%;">\n                        <table class="inner-body" align="center" width="570" cellpadding="0" cellspacing="0" style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; background-color: #FFFFFF; margin: 0 auto; padding: 0; width: 570px; -premailer-cellpadding: 0; -premailer-cellspacing: 0; -premailer-width: 570px;">\n                            <!-- Body content -->\n                            <tr>\n                                <td class="content-cell" style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; padding: 35px;">\n                                    @yield(\'content\')\n                                    <p style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; color: #74787E; font-size: 16px; line-height: 1.5em; margin-top: 0; text-align: left;">Regards,<br>{{ config(\'app.name\', \'Laravel\') }}</p>\n                                    @yield(\'subcopy\')\n                                </td>\n                            </tr>\n                        </table>\n                    </td>\n                </tr>\n\n                <tr>\n                    <td style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box;">\n                        <table class="footer" align="center" width="570" cellpadding="0" cellspacing="0" style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; margin: 0 auto; padding: 0; text-align: center; width: 570px; -premailer-cellpadding: 0; -premailer-cellspacing: 0; -premailer-width: 570px;">\n                            <tr>\n                                <td class="content-cell" align="center" style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; padding: 35px;">\n                                    <p style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; line-height: 1.5em; margin-top: 0; color: #AEAEAE; font-size: 12px; text-align: center;">\xc2\xa9 {{ date(\'Y\') }} {{ config(\'app.name\', \'Laravel\') }}. All rights reserved.</p>\n                                </td>\n                            </tr>\n                        </table>\n                    </td>\n                </tr>\n            </table>\n        </td>\n    </tr>\n</table>\n</body>\n</html>\n\n
Run Code Online (Sandbox Code Playgroud)\n