> ## Documentation Index
> Fetch the complete documentation index at: https://docs.law4devs.eu/llms.txt
> Use this file to discover all available pages before exploring further.

# Pagination

> How pagination works in the Law4Devs PHP SDK.

## Overview

All `list()` methods return a `Page<T>` object. Every page includes the data array, metadata about the total result set, and links to the next/previous page.

***

## The `Page` Object

```php theme={null}
$page = $client->articles->list('gdpr');

// Data
$articles = $page->data;          // ArticleSummary[]
$count    = $page->count();       // items on this page

// Metadata
$total   = $page->meta->total;    // total results across all pages
$current = $page->meta->page;     // current page number
$perPage = $page->meta->perPage;  // items per page
$pages   = $page->meta->pages;    // total number of pages

// Links
$nextUrl = $page->links->next;    // URL of next page (null if last)
$prevUrl = $page->links->prev;    // URL of previous page (null if first)
```

***

## Manual Pagination

Control pagination yourself with `$page` and `$perPage`:

```php theme={null}
$pageNum = 1;

do {
    $page = $client->articles->list('gdpr', page: $pageNum, perPage: 50);

    foreach ($page->data as $article) {
        echo $article->title . "\n";
    }

    $pageNum++;
} while ($page->links->next !== null);
```

***

## Auto-Pagination with `iter()`

Every resource exposes an `iter()` method that automatically fetches all pages and yields individual items:

```php theme={null}
// Yields ArticleSummary one by one — no manual paging needed
foreach ($client->articles->iter('gdpr') as $article) {
    echo $article->articleNumber . ' ' . $article->title . "\n";
}
```

Internally, `iter()` calls `list()` repeatedly, following `links->next` until there are no more pages.

<Tip>
  Use `iter()` whenever you need all items. It handles pagination transparently and uses PHP generators, so it doesn't load the full result set into memory at once.
</Tip>

***

## Collecting into an Array

If you need a full array, use `iterator_to_array()`:

```php theme={null}
$articles = iterator_to_array($client->articles->iter('cra'));
echo count($articles) . " total articles\n";
```

***

## Pagination Parameters

| Parameter  | Type        | Default | Description              |
| ---------- | ----------- | ------- | ------------------------ |
| `$page`    | `int\|null` | `1`     | Page number (1-indexed)  |
| `$perPage` | `int\|null` | `20`    | Items per page (max 100) |
