> 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/adapters.md).

# Adapters

Paginator behavior depends on which adapter you create.

## Array adapter

`ArrayPaginator` is the simple option for already-loaded data.

Use it when you have an in-memory array and want to slice it into pages without touching the database layer.

```php
$paginator = PaginatorFactory::create(PaginatorType::ARRAY, [
    'items' => $items,
    'perPage' => 20,
    'page' => 3,
]);
```

### Input contract

* `items` must be an array
* `perPage` is an integer
* `page` is an integer and defaults to `1`

### Returned data

* `data()` returns the current page slice as an array
* `firstItem()` and `lastItem()` return the first and last item from that slice
* when the current page has no items, `firstItem()` and `lastItem()` return `null`

### Good fit

Choose this adapter when the source data is already in memory, such as filtered config rows, API results you already fetched, or custom service output.

## Model adapter

`ModelPaginator` paginates a Quantum `DbModel` query.

Use it when you already have a model builder with criteria, ordering, or joins applied and you want a paginated result plus navigation metadata.

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

### Input contract

* `model` must be a `DbModel` instance
* `perPage` is an integer
* `page` is an integer and defaults to `1`

### Returned data

* `data()` returns a `ModelCollection`
* `firstItem()` and `lastItem()` return models from that collection or `null` when the page is empty

### Query behavior that affects usage

* Build your filters and sorting first, then create the paginator.
* `data()`, `firstItem()`, and `lastItem()` may each trigger data loading, so fetch once and reuse when possible.
* If you paginate a named model class, returned rows are hydrated back into that model type.

## Shared adapter behavior

Both adapters share the same paging metadata API through `PaginatorInterface`, including:

* current, previous, next, and last page numbers
* current, previous, next, first, and last page links
* `links()` for the full page list
* `getPagination()` for ready-made HTML output


---

# 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/adapters.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.
