dimanche 26 mars 2017

Laravel - unable to loop in the first relationship, but within the relationship works fine

My current nested for loop:

@foreach($auditResults->map->questionDetail as $detail)
    @include('dropdownQuestion', [
        'answer' => $auditResults,
        'detail' => $detail,
        'question' => $detail->auditQuestion
    ])
@endforeach

As you can see, I want to return the $auditResults within the loop as answer, but this current set up doesn't work.

If I change the for loop to this (which logically makes sense):

@foreach($auditResults as $result)
    @foreach($result->map->questionDetail as $detail)
        @include('dropdownQuestion', [
            'answer' => $result,
            'detail' => $detail,
            'question' => $detail->map->auditQuestion
        ])
    @endforeach
@endforeach

I get Trying to get property of non-object.

How can I loop and return the $auditResults without getting a non-object property? Many thanks.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2okisno
via IFTTT

Aucun commentaire:

Enregistrer un commentaire