Home > Enterprise >  Get tags in view blade depending on how data is cycled
Get tags in view blade depending on how data is cycled

Time:02-01

I have the code shown below.

Cycle the clinics; for each response, if the clinic id corresponds to the clinic id present in the response and if the guest id corresponds to the guest id present in the response I want it to print the date of the response otherwise the button to add the response.

As I did, the code prints me how many buttons (even if the date is present) how many responses, while as I said above, I want to get the button only if the date is not present.

<table id="tabledata" >
<thead>
    <tr>
    <th>Surname</th>
    <th>Name</th>
    <th>Phone</th>
    @foreach($clinics as $clinic)
        <th>{{$clinic->name}}</th>
    @endforeach
    </tr>
</thead>
<tbody>
    @foreach ($guests as $guest)
        <tr>
            <td>{{ $guest->surname }}</td>
            <td>{{ $guest->name }}</td>
            <td> <a href="tel:{{ $guest->phone }}"> {{ $guest->phone }}</a></td>
            @foreach($clinics as $clinic)
                <td>
                    @foreach($guest_responses as $guest_response)
                        @if(($guest->id == $guest_response->guest_id) && ($clinic->id == $guest_response->clinic_id))
                            <p>{{$guest_response->date}}</p>
                        @endif
                        <button type="button"  data-bs-toggle="modal" data-bs-target="#responseModal" data-id-clinic="{{$clinic->id}}" data-id-guest="{{$guest->id}}" data-name-clinic="{{$clinic->name}}" data-surname-guest="{{ $guest->surname }}" data-name-guest="{{ $guest->name }}"><i ></i></button>
                    @endforeach
                </td>
            @endforeach
        </tr>
    @endforeach
</tbody>
</table>

Can anyone help me?

CodePudding user response:

How about to add a flag to check a response with a date?

<td>
    @php
        $exist_response_date = false;
    @endphp
    @foreach($guest_responses as $guest_response)
        @if(($guest->id == $guest_response->guest_id) && ($clinic->id == $guest_response->clinic_id))
            @php
                if($guest_response->date) {
                    $exist_response_date = true;
                }
            @endphp
            <p>{{$guest_response->date}}</p>
        @endif
    @endforeach
    @if(!$exist_response_date)
        <button type="button"  data-bs-toggle="modal" data-bs-target="#responseModal" data-id-clinic="{{$clinic->id}}" data-id-guest="{{$guest->id}}" data-name-clinic="{{$clinic->name}}" data-surname-guest="{{ $guest->surname }}" data-name-guest="{{ $guest->name }}"><i ></i></button>
    @endif
</td>
  • Related