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
$dataReader = (new MyDataReader(...))->withSort($sort);
339
338
340
339
$paginator = (new KeysetPaginator($dataReader))
341
340
->withPageSize(10)
@@ -345,27 +344,26 @@ $paginator = (new KeysetPaginator($dataReader))
345
344
When displaying first page ID (or another field name to paginate by) of the item displayed last is used with `withNextPageToken()`
346
345
to get next page.
347
346
348
-
#### Page-by-page navigation
347
+
#### Iterate through all pages
349
348
350
349
Both `OffsetPaginator` and `KeysetPaginator` provide `nextPage()` and `previousPage()` methods for easy page-by-page data reading:
351
350
352
351
```php
353
352
$dataReader = (new QueryDataReader($query))->withSort(Sort::only(['id']));
354
-
$paginator = (new KeysetPaginator($dataReader))->withPageSize(1000);
355
353
356
-
// Iterate through all pages
357
354
for (
358
-
$currentPaginator = $paginator;
359
-
$currentPaginator !== null;
360
-
$currentPaginator = $currentPaginator->nextPage()
355
+
$paginator = (new KeysetPaginator($dataReader))->withPageSize(1000);
356
+
$paginator !== null;
357
+
$paginator = $paginator->nextPage()
361
358
) {
362
-
foreach ($currentPaginator->read() as $data) {
359
+
foreach ($paginator->read() as $data) {
363
360
// Process each item
364
361
}
365
362
}
366
363
```
367
364
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.
365
+
The `nextPage()` method returns a new paginator instance configured for the next page, or `null` when there are no more pages.
366
+
Similarly, `previousPage()` returns a paginator for the previous page, or `null` when at the first page.
0 commit comments