> For the complete documentation index, see [llms.txt](https://quantumphp.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://quantumphp.gitbook.io/docs/packages/paginator/overview.md).

# Overview

The Paginator package wraps paginated data behind one consistent API.

Use it when you need page-aware results, navigation links, or ready-made pagination HTML for either:

* plain PHP arrays
* Quantum `DbModel` queries

## What the package provides

The package centers on `Quantum\Paginator\Paginator`, a thin wrapper around one adapter instance. In practice, you usually create it through `PaginatorFactory` and then call the same methods regardless of data source.

Supported adapter types are:

* `PaginatorType::ARRAY`
* `PaginatorType::MODEL`

## Basic example

### Paginating an array

```php
use Quantum\Paginator\Enums\PaginatorType;
use Quantum\Paginator\Factories\PaginatorFactory;

$paginator = PaginatorFactory::create(PaginatorType::ARRAY, [
    'items' => $rows,
    'perPage' => 10,
    'page' => 2,
]);

$data = $paginator->data();
$links = $paginator->links();
$html = $paginator->getPagination();
```

### Paginating a model query

```php
use Quantum\Paginator\Enums\PaginatorType;
use Quantum\Paginator\Factories\PaginatorFactory;

$paginator = PaginatorFactory::create(PaginatorType::MODEL, [
    'model' => $postModel,
    'perPage' => 15,
    'page' => 1,
]);

$posts = $paginator->data();
```

## Defaults that matter

If you omit them, the factory applies these defaults:

* `perPage` -> `10`
* `page` -> `1`

Only the adapter-specific payload is required:

* array paginator requires `items`
* model paginator requires `model`

## Important constraints

* The package only ships the two built-in adapter types above.
* Unsupported adapter names fail with `PaginatorException::adapterNotSupported(...)`.
* Missing required adapter parameters fail with `PaginatorException::missingRequiredParams(...)`.
* `Paginator` forwards calls to its adapter. Calling a method the adapter does not implement fails with `PaginatorException::methodNotSupported(...)`.
* Page numbers are not normalized. If you pass a page beyond the available range, the paginator keeps that page number and the current page data can be empty.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://quantumphp.gitbook.io/docs/packages/paginator/overview.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
