nikocraft's avatar

problem with pagination

I have this code in controller where I get the tag based on slug and then all the posts belonging to the tag and I paginate them

        $tag = Tag::where('slug', $slug)->first();
        $posts = $tag->posts()->published()->paginate(1);
        return view('posts.tag')->withTag($tag)->withPosts($posts);

inside Post model

    public function tags()
    {
        return $this->belongsToMany(Tag::class);
    }

inside blade I do this:

{{ $posts->links() }}

Pagination links do not render. However I only see 1 post and if I add ?page=2 to the url I can see the second post. Do you have any idea why pagination links are not rendering?

0 likes
1 reply
lara28580's avatar

Hi try it with the render() method like so {!! $posts->render() !!}

Please or to participate in this conversation.