PHPackages                             askdkc/laravel-quick-paginator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. askdkc/laravel-quick-paginator

ActiveLibrary[Database &amp; ORM](/categories/database)

askdkc/laravel-quick-paginator
==============================

Speed up Laravel pagination by caching total counts and skipping repeated count queries.

v1.0.0(yesterday)027↑2677.8%MITPHPPHP ^8.3CI passing

Since Jun 18Pushed yesterdayCompare

[ Source](https://github.com/askdkc/laravel-quick-paginator)[ Packagist](https://packagist.org/packages/askdkc/laravel-quick-paginator)[ GitHub Sponsors](https://github.com/askdkc)[ Fund](https://ko-fi.com/askdkc)[ RSS](/packages/askdkc-laravel-quick-paginator/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (9)Versions (2)Used By (0)

Laravel Quick Paginator
=======================

[](#laravel-quick-paginator)

[![Latest Version on Packagist](https://camo.githubusercontent.com/34c6473dba88fa30a31f3fde7f68f77f26d2f27febad6f2c9cc0ef22d98d2f9b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61736b646b632f6c61726176656c2d717569636b2d706167696e61746f722e737667)](https://packagist.org/packages/askdkc/laravel-quick-paginator)[![GitHub Tests Action Status](https://github.com/askdkc/laravel-quick-paginator/actions/workflows/test.yml/badge.svg)](https://github.com/askdkc/laravel-quick-paginator/actions?query=workflow%3Atest+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/727d57d84c13acd018e76264df555aee0b5e9b8972081d53da267ccf974268a0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61736b646b632f6c61726176656c2d717569636b2d706167696e61746f722e737667)](https://packagist.org/packages/askdkc/laravel-quick-paginator)[![](https://camo.githubusercontent.com/d2432db86e1cfca636933728a664bf886cff501efab549a0af6abab26fe8851b/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d53706f6e736f72266d6573736167653d254532253944254134266c6f676f3d47697448756226636f6c6f723d253233666538653836)](https://github.com/sponsors/askdkc)

Laravel Quick Paginator caches only the `total` value used by Laravel's length-aware pagination. On later page requests, it passes that cached total into Laravel's native `paginate()` method so Laravel can skip the repeated pagination `count(*)` query.

It does not cache result rows, replace paginator classes, or change the normal `LengthAwarePaginator` response shape.

### 日本語

[](#日本語)

Laravel Quick Paginator は、Laravel の LengthAware Pagination で使われる total 値だけをキャッシュします。以降のページリクエストでは、そのキャッシュ済み total を Laravel 標準の paginate() メソッドに渡すことで、pagination のたびに繰り返される count(\*) クエリを Laravel に実行させないようにします。

このパッケージは、結果行をキャッシュしません。paginator クラスを置き換えることもありません。また、通常の LengthAwarePaginator のレスポンス形式も変更しません。

Benchmark
---------

[](#benchmark)

In this benchmark, both examples paginate a table with 5,000,000 posts.

Normal Laravel pagination finished in **795.90 ms**:

[![Normal pagination benchmark](images/normalpagination.png)](images/normalpagination.png)

Quick pagination finished in **264.69 ms**:

[![Quick pagination benchmark](images/quickpagination.png)](images/quickpagination.png)

That is roughly **3x faster** in this run. The gain comes from reusing the cached total count instead of repeating Laravel's expensive pagination count query on every page request. Query count alone may not always be lower because cache operations or application queries can still be recorded, but the costly `count(*)` work is avoided on cache hits.

### 日本語

[](#日本語-1)

このベンチマークでは、5,000,000 件の posts テーブルに対して pagination を実行しています。

通常の Laravel pagination は **795.90 ms** でした。

[![Normal pagination benchmark](images/normalpagination.png)](images/normalpagination.png)

Quick pagination は **264.69 ms** でした。

[![Quick pagination benchmark](images/quickpagination.png)](images/quickpagination.png)

この実行では、およそ **3 倍高速** になっています。高速化の理由は、ページ移動のたびに重い pagination 用の `count(*)` クエリを繰り返さず、キャッシュ済みの total 件数を再利用するためです。キャッシュ処理やアプリケーション側のクエリが記録されることがあるため、SQL query 数だけが常に少なくなるとは限りませんが、cache hit 時には高コストな `count(*)` を避けられます。

Installation
------------

[](#installation)

```
composer require askdkc/laravel-quick-paginator
```

Publish the config when you need to change the cache store, prefix, or TTL:

```
php artisan vendor:publish --tag=cached-pagination-config
```

### 日本語

[](#日本語-2)

インストールします。

```
composer require askdkc/laravel-quick-paginator
```

キャッシュストア、プレフィックス、TTL を変更したい場合は、設定ファイルを公開してください。

```
php artisan vendor:publish --tag=cached-pagination-config
```

Usage
-----

[](#usage)

Use `quickPaginate()` where you would normally use `paginate()`.

```
$users = User::query()
    ->where('active', true)
    ->quickPaginate(50);
```

Query builder usage is supported too:

```
$users = DB::table('users')
    ->where('active', true)
    ->quickPaginate(50);
```

The method signature stays close to Laravel's paginator:

```
quickPaginate(
    $perPage = null,
    $columns = ['*'],
    $pageName = 'page',
    $page = null,
    ?int $ttl = null,
    bool $fresh = false,
    ?string $cacheKey = null,
)
```

### 日本語

[](#日本語-3)

通常の `paginate()` を使う箇所で、代わりに `quickPaginate()` を使用します。

```
$users = User::query()
    ->where('active', true)
    ->quickPaginate(50);
```

Query Builder でも利用できます。

```
$users = DB::table('users')
    ->where('active', true)
    ->quickPaginate(50);
```

メソッドシグネチャは Laravel 標準の paginator に近い形になっています。

```
quickPaginate(
    $perPage = null,
    $columns = ['*'],
    $pageName = 'page',
    $page = null,
    ?int $ttl = null,
    bool $fresh = false,
    ?string $cacheKey = null,
)
```

追加パラメータとして、`$ttl`、`$fresh`、`$cacheKey` を指定できます。

- `$ttl` は、この pagination total 用のキャッシュ TTL を個別に指定します。
- `$fresh` に `true` を指定すると、キャッシュ済み total を使わずに再度 `count(*)` を実行し、キャッシュを更新します。
- `$cacheKey` を指定すると、独自のキャッシュキーで total 件数を保存できます。

Demo App
--------

[](#demo-app)

If you want to test this package in a real Laravel application, use the demo app here:

### 日本語

[](#日本語-4)

実際の Laravel アプリケーションで試したい場合は、こちらのデモアプリを使ってください。

Configuration
-------------

[](#configuration)

Default config:

```
return [
    'enabled' => true,
    'store' => null,
    'prefix' => 'cached-pagination-total',
    'ttl' => 300,
];
```

The default TTL is intentionally short because the package trades total freshness for fewer count queries. Set `store` to use a non-default Laravel cache store.

### 日本語

[](#日本語-5)

デフォルト設定は以下の通りです。

```
return [
    'enabled' => true,
    'store' => null,
    'prefix' => 'cached-pagination-total',
    'ttl' => 300,
];
```

デフォルト TTL は意図的に短めに設定されています。このパッケージは total 件数の厳密な最新性と、pagination 時の `count(*)` クエリ削減をトレードオフするためです。

`store` を指定すると、Laravel のデフォルトキャッシュストア以外を利用できます。

Refreshing Totals
-----------------

[](#refreshing-totals)

Pass `fresh: true` to bypass the cached total, run the count once, and replace the cache entry:

```
$users = User::query()->quickPaginate(50, fresh: true);
```

You may also provide a custom cache key:

```
$users = User::query()
    ->where('active', true)
    ->quickPaginate(50, cacheKey: 'users.active.total');
```

### 日本語

[](#日本語-6)

`fresh: true` を指定すると、キャッシュ済み total を無視し、一度だけ `count(*)` を実行してキャッシュを更新します。

```
$users = User::query()->quickPaginate(50, fresh: true);
```

独自のキャッシュキーを指定することもできます。

```
$users = User::query()
    ->where('active', true)
    ->quickPaginate(50, cacheKey: 'users.active.total');
```

Notes
-----

[](#notes)

Laravel Quick Paginator supports `Model::query()->quickPaginate()` and `DB::table(...)->quickPaginate()` in v1.

Relation-specific paginator methods are intentionally not promised yet because some relation classes do not expose Laravel's fifth `paginate()` `$total` argument directly. Cursor pagination and simple pagination are also out of scope because they do not use total counts in the same way.

### 日本語

[](#日本語-7)

v1 では、`Model::query()->quickPaginate()` と `DB::table(...)->quickPaginate()` をサポートしています。

Relation ごとの paginator メソッドについては、現時点ではサポートを保証していません。一部の Relation クラスでは、Laravel の `paginate()` が持つ第 5 引数 `$total` を直接公開していないためです。

Cursor Pagination と Simple Pagination も対象外です。これらは LengthAware Pagination と違い、同じ形で total 件数を利用しないためです。

Development
-----------

[](#development)

Install dependencies:

```
composer install
```

Run the Pest test suite:

```
composer test
```

Run Larastan static analysis:

```
composer analyse
```

### 日本語

[](#日本語-8)

依存パッケージをインストールします。

```
composer install
```

Pest テストを実行します。

```
composer test
```

Larastan による静的解析を実行します。

```
composer analyse
```

###  Health Score

43

—

FairBetter than 90% of packages

Maintenance100

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7894265?v=4)[askdkc](/maintainers/askdkc)[@askdkc](https://github.com/askdkc)

---

Top Contributors

[![askdkc](https://avatars.githubusercontent.com/u/7894265?v=4)](https://github.com/askdkc "askdkc (8 commits)")

---

Tags

laravelpagination

###  Code Quality

TestsPest

Static AnalysisPHPStan

### Embed Badge

![Health badge](/badges/askdkc-laravel-quick-paginator/health.svg)

```
[![Health](https://phpackages.com/badges/askdkc-laravel-quick-paginator/health.svg)](https://phpackages.com/packages/askdkc-laravel-quick-paginator)
```

###  Alternatives

[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8723.1M23](/packages/yajra-laravel-oci8)[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.0M86](/packages/mongodb-laravel-mongodb)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45344.0k1](/packages/pressbooks-pressbooks)[api-platform/laravel

API Platform support for Laravel

59156.3k11](/packages/api-platform-laravel)[ntanduy/cloudflare-d1-database

Cloudflare D1 database driver for Laravel — full Eloquent &amp; Query Builder support.

276.8k](/packages/ntanduy-cloudflare-d1-database)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
