Laravel blade check empty foreach

前端 未结 7 1969
轻奢々
轻奢々 2021-01-31 07:36

I want to check if my foreach is empty so the basic html markup isn\'t displayed with no results inside. I\'m trying to wrap it in an if statement and then if it is empty do not

7条回答
  •  野性不改
    2021-01-31 07:52

    Echoing Data If It Exists

    Sometimes you may wish to echo a variable, but you aren't sure if the variable has been set. We can express this in verbose PHP code like so:

    {{ isset($name) ? $name : 'Default' }}
    

    However, instead of writing a ternary statement, Blade provides you with the following convenient short-cut:

    {{ $name or 'Default' }}
    

    In this example, if the $name variable exists, its value will be displayed. However, if it does not exist, the word Default will be displayed.

    From https://laravel.com/docs/5.4/blade#displaying-data

提交回复
热议问题