How to echo a default value if value not set blade

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

    I recommend setting the default value in your controller instead of making a work-around in your view.

    This is the best way because it keeps logic out of your view, and keeps the view's markup clean.

    For example in your controller, before passing data to the view:

    if(!isset($foo['bar'])){
         $foo['bar'] = 'baz';
    }
    

提交回复
热议问题