Reputation: 3573
How do I escape out of blade syntax to show html in an if data exists statement?
{{ $manager->first_name or '<a href="/add">add</a>' }}
Will just show the html tags as well. All I saw in the docs was escap
Upvotes: 0
Views: 592
Reputation: 442
Just an addition to celia's answer; you should still escape the data:
{!! isset($manager->first_name) ? e($manager->first_name) : '<a href="/add">add</a>' !!}
Upvotes: 1
Reputation: 33
you can do this {!! $manager->first_name or '<a href="/add">add</a>' !!}
Upvotes: 1
Reputation: 5781
That kind of logic is not the best way to do things... In your view, You should do the following
@if (null !== $manager->first_name)
{{ $manager->first_name }}
@else
<a href="/add">add</a>
@endif
There may be some changes needed to the code for the if/else statement to validate correctly, but this is the basic idea.
Upvotes: 5