Уведомление Laravel Хотите использовать представление html в шаблоне блейда уведомлений

Я использую Laravel версии 5.7.20 для создания пользовательского шаблона уценки. Шаблон копируется из /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('/'));

image

Это не работает. Который использует мою собственную уценку

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

image

мой файл 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 в уведомлении по электронной почте?


person Shiro    schedule 16.01.2019    source источник
comment
Чего вы на самом деле пытаетесь достичь здесь? Вы хотите, чтобы html-теги работали, когда они выводятся в виде текста? Или вы хотите просто использовать файл шаблона вместо создания объекта MailMessage?   -  person Mike Harrison    schedule 16.01.2019
comment
Я хочу, чтобы мой шаблон блейда-уведомления мог отображать правильный html, а не htmlspecialchars или закодированную версию. Как видите, в таблице html показан исходный код, а полужирный текст не отображается, он заменен на тег.   -  person Shiro    schedule 17.01.2019


Ответы (1)


Хорошо, я нашел ошибку.

Если вы хотите использовать ->view(), шаблон блейда не может использовать @component('mail::message'), он должен быть создан с новым макетом блейда (создайте собственное представление, как обычную страницу). Тогда вы не получите No hint path defined for [mail] ошибки.

Laravel Notification Разметьте многое, чтобы изучить их синтаксис и их экосистему. Это отлично подходит для тех, кто хочет простое уведомление. Но если вам нужна пользовательская страница, я бы предложил использовать view().

Я делюсь своим файлом макетного блейда, который копирую после отправки из уценки. В содержательной части у вас своя логика.

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

email_layout.blade.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<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;">
<style>
    @media  only screen and (max-width: 600px) {
        .inner-body {
            width: 100% !important;
        }

        .footer {
            width: 100% !important;
        }
    }

    @media  only screen and (max-width: 500px) {
        .button {
            width: 100% !important;
        }
    }
</style>

<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%;">
    <tr>
        <td align="center" style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box;">
            <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%;">
                <tr>
                    <td class="header" style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; padding: 25px 0; text-align: center;">
                        <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;">
                            {{ config('app.name', 'Laravel') }}
                        </a>
                    </td>
                </tr>


                <!-- Email Body -->
                <tr>
                    <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%;">
                        <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;">
                            <!-- Body content -->
                            <tr>
                                <td class="content-cell" style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; padding: 35px;">
                                    @yield('content')
                                    <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>
                                    @yield('subcopy')
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>

                <tr>
                    <td style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box;">
                        <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;">
                            <tr>
                                <td class="content-cell" align="center" style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; padding: 35px;">
                                    <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;">© {{ date('Y') }} {{ config('app.name', 'Laravel') }}. All rights reserved.</p>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
</body>
</html>

person Shiro    schedule 30.01.2019