vendredi 19 juillet 2019

Blade Foreach and if statements, 2nd itteration returns true for 9 == 2

I am working on a Laravel PHP application for digital signatures,

currently in one of my blade files i have a foreach that is designed to add all the documents one at a time (on there own blade file)

however I have an issue where after the first iteration of my loop, my if statements designed to filter out only documents where the signer is defined (so that users who don't have to sign, don't see documents) are returning true for things such as ($document->responsible_signer == $user->id && $document->packet->live) where $document->responsible_signer == 9 and $user->id == 2

it works fine on the 1st iteration, but not the second.

I have simplified the code to reduce it's complexity and tried moving around which fields get called first with no change in the results, indicating it happens after the 1st iteration and not as a result of the if statements being funky

<div class="row justify-content-center">
    @foreach($facilityDocs->where('completed_at', null) as $document)
        @if($document->user_id == $user->id && $document->packet->live)
            <div class="col-4 my-3">
                @include('patient._document_card', ['document' => $document])
            </div>
        @endif
        @if($document->responsible_signer == $user->id && $document->packet->live)
            <div class="col-4 my-3">
                @include('patient._document_card', ['document' => $document])
            </div>
        @endif
        @if($document->responsible_two_signer == $user->id && $document->packet->live)
            <div class="col-4 my-3">
                @include('patient._document_card', ['document' => $document])
            </div>
        @endif
        @if($document->witness_signer == $user->id && $document->packet->live)
            <div class="col-4 my-3">
                @include('patient._document_card', ['document' => $document])
            </div>
        @endif
        @if($document->community_signer == $user->current_facility_id && $document->packet->live)
            <div class="col-4 my-3">
                @include('patient._document_card', ['document' => $document])
            </div>
        @endif
    @endforeach
</div>

the expected result is to show only documents where as an example

$document->witness_signer == $user->id

if this is true, it returns the document, otherwise it doesn't

Aucun commentaire:

Enregistrer un commentaire