0

I have the same code notification in Laravel 5.5 and 5.7, for Laravel 5.5, I am able to use <strong> in ->line, but in 5.7 it will escape it.

In my notification blade view file, I set {{ ]} or {!! !!}, I still can't display html in my email. In 5.5, I do not need to escape it still work.

\\this is when I not escape
&lt;strong&gt;2019-01-13 15:41&lt;/strong&gt;



 \\this is when I escape
 <strong>2019-01-13 15:37</strong>

what I want is display bold like below.

2019-01-13 15:37

both method also displayed the tag, It will not bold the text. The same coding work in 5.5 but not Laravel version 5.7.20

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
Shiro
  • 7,344
  • 8
  • 46
  • 80

2 Answers2

3

According to @driesvints

You don't need withoutDoubleEncoding in 5.7 so you can remove that.

As you can see lines are being escaped in the template:

framework/src/Illuminate/Notifications/resources/views/email.blade.php

Line 15 in d818fd1

{{ $line }} So you'll need to indicate that the line has HTML in it. Try this:

->line(new HtmlString('Due Date: ' . Carbon::parse($this->info->created_at)->format('Y-m-d H:i').''));

This is solution. Thanks!

Shiro
  • 7,344
  • 8
  • 46
  • 80
2

From 5.5 to 5.6 upgrade, the Laravel blade double encoding is removed. If you would like to maintain the previous behaviour of preventing double encoding, you may use the Blade::withoutDoubleEncoding method like the following.

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
  /**
   * Bootstrap any application services.
   *
   * @return void
   */
   public function boot()
   {
       Blade::withoutDoubleEncoding();
   }
}

You can read more about it on Laravel Documentation.

Set Kyar Wa Lar
  • 4,488
  • 4
  • 30
  • 57
usrNotFound
  • 2,680
  • 3
  • 25
  • 41
  • I added the `Blade::withoutDoubleEncoding();` , and `return (new MailMessage)->line('Due Date: 123');` still cannot get the bold font. Can you test? – Shiro Jan 14 '19 at 06:27