Ternary in Laravel Blade

后端 未结 5 1196
刺人心
刺人心 2020-12-23 11:02

Looking for a ternary operator for blade templates

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

Can\'t seem to get it to work this works

         


        
5条回答
  •  北荒
    北荒 (楼主)
    2020-12-23 12:01

    For Laravel 5 + php7, you should be using the null coalesce operator as explained in this Laravel News article, like so:

    {{ $value ?? "Fallback" }}
    

    Before the null coalescing operator, Blade handled the same problem with the “or” operator, which allows a default value when the first value isn’t set, separated by an “or”.

提交回复
热议问题