php - Laravel check if collection is empty -


i've got in laravel webapp:

@foreach($mentors $mentor)     @foreach($mentor->intern $intern)         <tr class="table-row-link" data-href="/werknemer/{!! $intern->employee->employeeid !!}">             <td>{{ $intern->employee->firstname }}</td>             <td>{{  $intern->employee->lastname }}</td>         </tr>     @endforeach @endforeach 

how check if there $mentors->intern->employee ?

when :

@if(count($mentors)) 

it not check that.

you can count collection. example $mentor->intern->count() return how many intern mentor have.

https://laravel.com/docs/5.2/collections#method-count

in code can this

foreach($mentors $mentor)     @if($mentor->intern->count() > 0)     @foreach($mentor->intern $intern)         <tr class="table-row-link" data-href="/werknemer/{!! $intern->employee->employeeid !!}">             <td>{{ $intern->employee->firstname }}</td>             <td>{{  $intern->employee->lastname }}</td>         </tr>     @endforeach     @else         mentor don't have intern     @endif @endforeach 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -