My Controller method is:
$topics=Topic::with(array('subtopics'=>function($query){
$query->orderBy('glc_subtopic_priority','asc');
}))->with('subtopics.resources')->find($id)->paginate(1);
return View::make('subtopics.index')->with('topics', $topics);
I am eager loading this and it works fine. But now I want to paginate this. I have tried
{{ dd($topics->toArray()) }}
and it returns me this:
array (size=7)
'total' => int 2
'per_page' => int 1
'current_page' => int 1
'last_page' => int 2
'from' => int 1
'to' => int 1
'data' =>
array (size=1)
0 =>
array (size=5)
'id' => int 1
...........
The problem is when I am displaying the data. I am using
@foreach($topics->subtopics as $topic)
<li>{{ $topics->glc_subtopic_name }}</li>
{{ $topic->glc_subtopic_content }}
@foreach($topic->resources as $resource)
<br/>{{ $resource->glc_subtopic_resource_url }}
@endforeach
@endforeach
This returns me the error:
Undefined property: Illuminate\Pagination\Paginator::$subtopics
How should I access the data in the paginated variable $topics
.