How to echo a default value if value not set blade

前端 未结 6 1249
迷失自我
迷失自我 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 09:13

    Use php's null coalesce operator:

    {{ $variable ?? "Default Message" }}
    

    Removed as of Laravel 5.7

    With Laravel 4.1-5.6 you could simply do it like this:

    {{ $variable or "Default Message" }}
    

    It's the same as:

    echo isset($variable) ? $variable : 'Default Message'; 
    

提交回复
热议问题