How to echo a default value if value not set blade

前端 未结 6 1250
迷失自我
迷失自我 2020-12-13 08:31

I would like to know what would be the best way to display a default value if the given value is not set. I have the following in a blade file (I can not guaranty that the k

6条回答
  •  爱一瞬间的悲伤
    2020-12-13 08:52

    PHP 5.3's ternary shortcut syntax works in Blade templates:

    {{ $foo->bar ?: 'baz' }}
    

    It won't work with undefined top-level variables, but it's great for handling missing values in arrays and objects.

提交回复
热议问题