dimanche 26 mars 2017

Laravel - Looping through a nested collection

Function to get all the required data:

$auditResults = Audit::where('audit_id', $id)
    ->with('questionDetail')
    ->with('questionDetail.auditQuestion')
    ->get();

Which returns (streamlined):

Audit {#427 ▼
  #relations: array:1 [▼
    "questionDetail" => AuditQuestionDetail {#449 ▼
      #relations: array:1 [▼
        "auditQuestion" => AuditQuestion {#471 ▼
          #original: array:5 [▶]
        }
      ]
    }
  ]
}

How can I loop within the view, to reach the auditQuestion relationship, for each Audit?

I have tried:

@foreach($auditResults->questionDetail->auditQuestion as $answer)

But I get:

Undefined property: Illuminate\Database\Eloquent\Collection::$questionDetail

Many thanks.



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

Aucun commentaire:

Enregistrer un commentaire