What is the difference between {{ }} and {!! !!} in laravel blade files?

Kumaran picture Kumaran · Jan 27, 2016 · Viewed 36.2k times · Source

In the laravel framework we can use blade to add PHP code in html file.
We are using both {{ }} and {!! !!} syntax in blade files of Laravel.
What is the difference between them?

Answer

Narendrasingh Sisodia picture Narendrasingh Sisodia · Jan 27, 2016

Blade {{ }} statements are automatically sent through PHP's htmlentities function to prevent XSS attacks.

If you pass data from your Controller to a View with some HTML styling like:

$first = "<b>Narendra Sisodia</b>";

And it is accessed, within Blade, with {{ $first }} then the output'll be:

<b>Narendra Sisodia</b>

But if it is accessed with {!! $first !!} then the output'll be:

Narendra Sisodia