Home > Net >  Pagination next page refreshes same data
Pagination next page refreshes same data

Time:01-10

I'm trying to do pagination and it's working fine. but i'm having little problem.

$selectedCategory = Course::where('course_category_id', $category->id)
                            ->StatusOn()
                            ->orderBy('created_at', 'desc')
                            ->paginate(9);

when i added orderBy and when i'm clicking on next page it's getting same courses that was in first page and it's orderBy fault. But i need orderBy so what can i do?

CodePudding user response:

You are using offset pagination, some results can occur again, so you can try cursor pagination. read the difference between offset and cursor pagination

CodePudding user response:

It was

->orderBy('id')

$selectedCategory = Course::where('course_category_id', $category->id)->StatusOn()->orderBy('created_at', 'desc')->orderBy('id')->paginate(18);

problem now it's work fine : ) thanks all for response )

  •  Tags:  
  • Related