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