Ternary in Laravel Blade

LeBlaireau picture LeBlaireau · Aug 13, 2014 · Viewed 83k times · Source

Looking for a ternary operator for blade templates

@if(Auth::check()) ? yes : no @endif

Can't seem to get it to work this works

@if(Auth::check()) yes @else no @endif

suppose there is not much in it for this example, just curious.

Answer

Marwelln picture Marwelln · Aug 13, 2014

You are free to use it with {{ }}.

{{ Auth::check() ? 'yes' : 'no' }}