Laravel check if collection is empty

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

I\'ve got this in my Laravel webapp:

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

        
7条回答
  •  Happy的楠姐
    2020-12-08 00:34

    Starting from Laravel 5.3 you can simply use :

    if ($mentor->isNotEmpty()) {
    //do something.
    }
    

    Documentation https://laravel.com/docs/5.5/collections#method-isnotempty

提交回复
热议问题