How to get first value returned by foreach

0

I am new to programming and am trying to solve my problem with foreach ...

I have a foreach that returns me the groups of photos that have photos in them ... however I need to get the first group that the foreach find photos and apply the checked attribute on the input tag of it ... I tried to do with empty however I can not ... Follow the code below ... Thank you! Hugs!

@foreach($property_get->getPhotoGroupList() as $key => $grupo)
  <input id="tab{{ $key }}" type="radio" name="tabs" {{  !empty($key) ? 'checked'  :  ' ' }}>
  <label class="band band-two lastWord" for="tab{{ $key }}">{{ $grupo->getName() }}</label>@endforeach
    
asked by anonymous 08.03.2018 / 15:09

1 answer

1

veirifica if the key is the first key if yes mark checked otherwise it does not tag

@foreach($property_get->getPhotoGroupList() as $key => $grupo)
    <input id="tab{{ $key }}" type="radio" name="tabs" {{  @if($key == 0) ? 'checked'  :  ' ' }}>
    <label class="band band-two lastWord" for="tab{{ $key }}">{{ $grupo->getName() }}</label>
@endforeach
    
08.03.2018 / 15:33