Laravel check if collection is empty

前端 未结 7 1144
清酒与你
清酒与你 2020-12-08 00:10

I\'ve got this in my Laravel webapp:

@foreach($mentors as $mentor)
    @foreach($mentor->intern as $intern)
        

        
相关标签:
7条回答
  • 2020-12-08 00:58

    This is the fastest way:

    if ($coll->isEmpty()) {...}
    

    Other solutions like count do a bit more than you need which costs slightly more time.

    Plus, the isEmpty() name quite precisely describes what you want to check there so your code will be more readable.

    0 讨论(0)
提交回复
热议问题