You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+22Lines changed: 22 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -345,6 +345,28 @@ $paginator = (new KeysetPaginator($dataReader))
345
345
When displaying first page ID (or another field name to paginate by) of the item displayed last is used with `withNextPageToken()`
346
346
to get next page.
347
347
348
+
#### Page-by-page navigation
349
+
350
+
Both `OffsetPaginator` and `KeysetPaginator` provide `nextPage()` and `previousPage()` methods for easy page-by-page data reading:
351
+
352
+
```php
353
+
$dataReader = (new QueryDataReader($query))->withSort(Sort::only(['id']));
354
+
$paginator = (new KeysetPaginator($dataReader))->withPageSize(1000);
355
+
356
+
// Iterate through all pages
357
+
for (
358
+
$currentPaginator = $paginator;
359
+
$currentPaginator !== null;
360
+
$currentPaginator = $currentPaginator->nextPage()
361
+
) {
362
+
foreach ($currentPaginator->read() as $data) {
363
+
// Process each item
364
+
}
365
+
}
366
+
```
367
+
368
+
The `nextPage()` method returns a new paginator instance configured for the next page, or `null` when there are no more pages. Similarly, `previousPage()` returns a paginator for the previous page, or `null` when at the first page.
0 commit comments