How to echo a default value if value not set blade

前端 未结 6 1247
迷失自我
迷失自我 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

    While Chris B's answer is perfectly valid; I felt perhaps this is a question that can have an alternative answer. Some would prefer not to make their controllers "fat" and in this case at least, the use of a Presenter could be the answer you seek for allowing a great deal of flexibility in your application views.

    Take a look at the following project/package on Github. The readme is pretty robust with a number of examples to get you going.

    It will allow you to do just what you asked and simply call

    {{ $foo['bar'] }}
    

    in your view.

提交回复
热议问题