I have a loop that allows me to display my visitors’ information from a JSON variable. I want to test if a visitor is in “depart” state (i.e. if the value of “depart” in my visitors JSON variable is not null). If this value is null, I display a “checkbox” type input. Otherwise, I display a form and an icon.
However, I have a problem: when the @else is triggered, the first iteration never displays the form, although the icon appears correctly. This problem occurs both when I have a single iteration and with multiple iterations.
@for($i = 0; $i < count($vt->visiteurs); $i++)
<div>
<span class="text-4xl font-bold
@if ($vt->arrivee < date('Y-m-d H:i', strtotime(date('Y-m-d H:i'). ' - 11 hours')))
text-red-500
@elseif($vt->depart != null)
text-black
@else
text-yellow-500
@endif">
{{$vt->badge[$i]->numero}}
</span>
</div>
<div class="col-span-3">
<span class="font-bold">Visiteur :</span> {{$vt->visiteurs[$i]['name']}} {{$vt->visiteurs[$i]['firstname']}} / <span class="font-bold">Société :</span>
@php
$societe = $vt->getSocieteForVisiteur($i);
@endphp
@if($societe)
{{$societe->name}}
@endif
</div>
<div>
@if($vt->visiteurs[$i]['depart'] != null)
<span class="text-red-500 font-bold">Départ</span>
@else
<span class="text-green-500 font-bold">Sur site</span>
@endif
</div>
<div>
@if($vt->visiteurs[$i]['depart'] == null)
<input type="checkbox" class="form-check-input" name="vis[]" value="{{$i}}">
@else
<form action="{{ route('visite.cancelsortie') }}" method="POST" class="cancel">
@csrf
<input type="number" name="visite_id" value="{{ $vt->id }}" hidden>
<input type="number" name="index" value="{{ $i }}" hidden>
<i class="fa-solid fa-xmark text-red-500 text-xl"></i>
</form>
@endif
</div>
@endfor
Why is the form not appearing on the first iteration even though the icon is showing correctly, and how can I fix this?
I tried to put a class on each of my forms, give them a different id, check the “depart” value with a dump. However nothing worked.