Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ftrillo's avatar

@jirdw but the url he showed contains both the slug he's using to get the post and the page route parameter. What else would he need to append?

jlrdw's avatar

@ftrillo OP needs to write a view to display his data for testing. If the paginator won't work there it will never work.

Snapey's avatar

@jlrdw please read the whole thread not just jump in at the end with obs that take us back 2 days

jlrdw's avatar

@Snapey I did, he said same info was showing on page 2. The parameter (slug) isn't being included, he is just paginating page 1 over and over.

Probably needs a length aware paginator for pretty url.

mlazuardy's avatar

sorry to bother you guys, I'm working on this website alone because my friends just don't want to help me, while I have to go to college till night. this makes my brain performance decrease and can not make logic

Snapey's avatar

@jlrdw if the slug was not included then the post would not be loaded. It is. The op is trying to pagination through related comments not the subject of the slug

ftrillo's avatar

@shawnmilke1 that's fine. I'm not a good person, just bored.

At this point I probably want to see what's wrong as much as you do.

Let's check some stuff and see If the problem becomes clear.

Please, check the ammount of comments the post in question has.

dd(Comment::where('post_id', $post->id)->count());

Then let's see what queries Laravel is running to paginate stuff: Put the code bellow in your controller show function, then navigate from page 1 to page 2. And show us what queries were saved to the laravel log.

public function show ($slug)
{
    \DB::enableQueryLog(); // this enables query logging

    $post = Post::where('slug',$slug)->firstOrFail();
    
    $commentPaginator = Comment::where('post_id',$post->id)->paginate(10);
    
    \Log::info(\DB::getQueryLog()); // this writes the queries in your log

    return view('post.show')
        ->with(['post'=>$post,'commentPaginator'=>$commentPaginator]);
}
Previous

Please or to participate in this conversation.