pogbamessi
pogbamessi

Reputation: 333

Pagination in laravel not generating links on views

I am trying to show all the blogs on one page but want to paginate them. The pagination works but the links don't seem to appear in the view. It keeps showing me this error:

Call to undefined method Illuminate\Database\Eloquent\Collection::links()

Here's the code:

public static function all()
{
  return \ExpoPost::with('attachment')->published()->type('post')->orderBy('post_date')->paginate(5);
}       

And in the view I am trying to do something like this

@foreach($posts as $post)
  <p>{{$post->post_title}}</p>
@endforeach
<p>{{$posts->links()}}</p>

Can someone please help me out?

Upvotes: 0

Views: 720

Answers (1)

retrograde
retrograde

Reputation: 2979

The problem is that pagination doesn't work with eager loading. This question goes into detail Laravel 4.1: How to paginate eloquent eager relationship?

So if you want to paginate, you will need change your query use the eloquent "where" or a fluent query.

Upvotes: 0

Related Questions