deekepMaks's avatar

Sort by created_at with cursor pagination

I am using mongodb as a database (jenssegers/mongodb). I created a method to get users sorted by their account creation. There are more than 10 users, the first 10 are retrieved with the correct sorting, but when I get the next page, I get empty data, as if there are no more users.

public function getUsers() {
        return User::orderBy('created_at', 'desc')->cursorPaginate(10);
}
0 likes
2 replies
Nakov's avatar

Here is a great post about it: https://laravel-news.com/cursor-pagination

Specifically this comment: As you can see, you cannot rely on the ?page=2 query param used for offset pagination. You must use the provided next_page_url param to get the next page of results.

Please or to participate in this conversation.