Laravel blade check empty foreach

前端 未结 7 1857
轻奢々
轻奢々 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 08:16

    It's an array, so ==== '' won't work (the === means it has to be an empty string.)

    Use count() to identify the array has any elements (count returns a number, 1 or greater will evaluate to true, 0 = false.)

    @if (count($status->replies) > 0)
     // your HTML + foreach loop
    @endif
    
    0 讨论(0)
提交回复
热议问题