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.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire