adam78
adam78

Reputation: 10078

How to include html tags to laravel flash message?

Is there a way to include html tags within a flash message. I have the following but the tags get escaped when rendered in blade?

 flash()->success('Confirmation email sent to <strong>' . $user->email . '</strong>');

Upvotes: 5

Views: 4283

Answers (1)

GWed
GWed

Reputation: 15673

You will have to use the unescaped syntax of blade

{!! $flashData !!}  // unescaped variable

Instead of:

{{ $flashData }}  // escaped variable

The escaped syntax is best to use by default as it stops a misbehaving user supplying <script> tags and javascript code as input to your app. If the html tags and javascript were not removed, this could be a security issue. So I would be very careful about unescaping data unless you are 100% sure its safe.

Also, just something to think about: why do you need the html in the flash data? Why can't you just send the $user->email by itself, and leave the view figure out how to render it. Keep your html markup in your view - this is much cleaner.

See the docs http://laravel.com/docs/5.1/blade#displaying-data search for "Displaying Unescaped Data"

Upvotes: 18

Related Questions