jeudi 20 juillet 2017

How to collect data using multiple eager loading in laravel 5

I'm just wondering why my code is not working, I mean, after I collect single data using eager loading, after that, if I collect the nested relationship, it returns an error. Please see my code below.

Error

Trying to get property of non-object

My Code

Controller.php

$exam = Exam::with('answers', 'child.answers')->find($id);
$exam = collect($exam->answers);
$exams = $quizzes->merge(collect($exam->child->answers));

return view('school.exam.view', compact('exams'));



view.blade.php

@foreach($exams as $exam)
  <li></li>
@endforeach




What should I do with this?



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

Aucun commentaire:

Enregistrer un commentaire