Laravel: HTML in notification



PHP Snippet 1:

<?php

namespace App\Notifications;

use Illuminate\Notifications\Messages\MailMessage;

class MailExtended extends MailMessage
{
    /**
     * The notification's data.
     *
     * @var string|null
     */
    public $viewData;

    /**
     * Set the content of the notification.
     *
     * @param string $greeting
     *
     * @return $this
     */
    public function content($content)
    {
        $this->viewData['content'] = $content;

        return $this;
    }

    /**
     * Get the data array for the mail message.
     *
     * @return array
     */
    public function data()
    {
        return array_merge($this->toArray(), $this->viewData);
    }
}

PHP Snippet 2:

return (new MailMessage())

PHP Snippet 3:

return (new MailExtended())

PHP Snippet 4:

@if (isset($content))
<hr>
    {!! $content !!}
<hr>
@endif

PHP Snippet 5:

->line(new HtmlString("<b>This is bold HTML text</b>"))

PHP Snippet 6:

use Illuminate\Support\HtmlString;

PHP Snippet 7:

@if (isset($content))
<hr>
{!! $content !!}
<hr>
@endif