Laravel nested foreach by 2 different Models
Laravel nested foreach by 2 different Models I tried this. problem is, How to foreach data from different Models? Trying to get property of non-object (View: C:wamp64wwwzainsurgaltresourcesviewschoicesindex.blade.php) Controller $duplicates = Question::selectRaw("count('id') as total, topic_id")->with('topic', 'topic.choices')->groupBy('topic_id')->get(); $choices = Choice::where('user_id',Auth::id())->pluck('question_number')->toArray(); return view('choices.index',compact('duplicates','choices')); View @foreach ($duplicates as $duplicate) <tr> <td style="text-align: center;">{{ $duplicate->topic->id }}</td> <td style="text-align: center;">{{ $duplicate->topic->title }}</td> <td style="text-align: center;">{{ $duplicate->total }}</td> <td style=...