0
votes

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?

1
That looks right. if you remove <p>{{$posts->links()}}</p> does your @foreach display?retrograde
yes my @foreach works finepogbamessi

1 Answers

0
votes

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.