Search code examples
formslaravel

What is the difference between `{{ }}` and `{!! !!}` when using forms?


I'm learning Laravel but I am confused. When using forms, what is the difference between using exclamation marks vs another curly bracket? Both seem to accomplish the same thing.

{!! Form::open(array('route' => 'post_store', 'class' => 'form')) !!}

{{ Form::open(array('route' => 'post_store', 'class' => 'form')) }}


Solution

  • {!! !!} will prevent to escape your data.

    By default, Blade {{ }} statements are automatically sent through PHP's htmlspecialchars() function to prevent XSS attacks.

    A questionable use for this would be, for example, injecting HTML fragments to make links clickable when the browser renders the templates' output, compare Displaying Unescaped Data (Laravel Blade).

    So if $data = "<a href=https://example.net>click me</a>;, for example,

    {{ $data }} is not clickable.

    {!! $data !!} will be clickable.