use Illuminate\Pagination\Cursor;
...
$nextCursor = $request->has('cursor') ? $request->get('cursor') : null;
$comments = Comment::cursorPaginate(20, ['*'], 'cursor', Cursor::fromEncoded($nextCursor));
// to get pagination metadata
$nextCursor = $comments->nextCursor()->encode();
$nextPageUrl = $comments->nextPageUrl();
$prevCursor = $comments->previousCursor()->encode();
$prevPageUrl = $comments->previousPageUrl();
$path = $comments->path();
Created
May 15, 2023 04:58
-
-
Save jaygaha/4592b1e403618387df6f81d4143f5b34 to your computer and use it in GitHub Desktop.
Cursor pagination will offer better performance if the "order by" columns are indexed. To go next or previous page we can define as.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment