sonali1908's avatar

Pagination and Eager Loading

My Controller method is:

$topics=Topic::with(array('subtopics'=>function($query){ $query->with('resources')->orderBy('glc_subtopic_priority','asc')->paginate(1); }))->find($id); return View::make('subtopics.index')->with('topics', $topics); I am eager loading this and it works fine. But now I want to paginate this.

The problem is when I am displaying the data. I am using

@foreach($topics->subtopics as $topic)

  • {{ $topics->glc_subtopic_name }}
  • {{ $topic->glc_subtopic_content }} @foreach($topic->resources as $resource)
    {{ $resource->glc_subtopic_resource_url }} @endforeach @endforeach

    This returns me the expected result.

    But, when I use $topics->links() it returns me an error: Call to undefined method Illuminate\Database\Query\Builder::links()

    How can I access this?

    0 likes
    0 replies

    Please or to participate in this conversation.