1
votes

I have a PHP variable in Laravel controller: $html= '<img src="/example.png">'

Then in view blade, I displayed it with {{$html}}.

But it isn't rendered as html element. It shows as a text/string like <img src="/example.png"> in browser.

2

2 Answers

3
votes

You should use:

{!! $html !!}

Check this answer, it is also documented on the official documentation, on the section Displaying Unescaped Data

0
votes

Displaying Unescaped Data

By default, Blade {{ }} statements are automatically sent through PHP's htmlentities function to prevent XSS attacks. If you do not want your data to be escaped, you may use the following syntax:

Hello, {!! $name !!}.

Ref. https://laravel.com/docs/5.1/blade#displaying-data