Skip to content

Commit

Permalink
[9.x] Expose next and previous cursor of cursor paginator (#41001)
Browse files Browse the repository at this point in the history
* Expose raw next/previous cursors

* Change suffix from 'page' to 'cursor'

* Update tests
  • Loading branch information
gdebrauwer authored Feb 15, 2022
1 parent ba4b11d commit 8e15796
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Illuminate/Pagination/CursorPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ public function toArray()
'data' => $this->items->toArray(),
'path' => $this->path(),
'per_page' => $this->perPage(),
'next_cursor' => $this->nextCursor()?->encode(),
'next_page_url' => $this->nextPageUrl(),
'prev_cursor' => $this->previousCursor()?->encode(),
'prev_page_url' => $this->previousPageUrl(),
];
}
Expand Down
2 changes: 2 additions & 0 deletions tests/Integration/Http/ResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,8 @@ public function testCursorPaginatorReceiveLinks()
'meta' => [
'path' => '/',
'per_page' => 1,
'next_cursor' => (new Cursor(['id' => 5]))->encode(),
'prev_cursor' => null,
],
]);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/Pagination/CursorPaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public function testReturnsRelevantContextInformation()
'data' => [['id' => 1], ['id' => 2]],
'path' => '/',
'per_page' => 2,
'next_cursor' => $this->getCursor(['id' => 2]),
'next_page_url' => '/?cursor='.$this->getCursor(['id' => 2]),
'prev_cursor' => null,
'prev_page_url' => null,
];

Expand Down

0 comments on commit 8e15796

Please sign in to comment.