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.
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.
You should use:
{!! $html !!}
Check this answer, it is also documented on the official documentation, on the section Displaying Unescaped Data
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 !!}.