PHPackages                             augmentmy/laravel-query-pagination - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. augmentmy/laravel-query-pagination

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

augmentmy/laravel-query-pagination
==================================

Reusable pagination, filtering, sorting helper for Laravel APIs

v0.1.3(5mo ago)013MITPHPPHP &gt;=8.1

Since Nov 20Pushed 5mo agoCompare

[ Source](https://github.com/Joshua-Augment/laravel-query-pagination)[ Packagist](https://packagist.org/packages/augmentmy/laravel-query-pagination)[ RSS](/packages/augmentmy-laravel-query-pagination/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (6)Versions (5)Used By (0)

Laravel Query Pagination
========================

[](#laravel-query-pagination)

A lightweight package for building **consistent, API-friendly pagination, sorting, filtering, and search** endpoints in Laravel — now using a **single unified class (`PaginatedQuery`)** for both querying and responding.

This package standardizes the query params and JSON output across all your endpoints, making it simple for your frontend (React, Vue, mobile apps) to plug in one standard pattern.

---

🚀 Installation
--------------

[](#-installation)

```
composer require augmentmy/laravel-query-pagination
```

The service provider is auto‑discovered.

### Requirements

[](#requirements)

- PHP `>= 8.1`
- Laravel `10.x` or `11.x`
- Eloquent ORM (`illuminate/database`)

---

🔌 Unified Usage
---------------

[](#-unified-usage)

The package now exposes ONE primary class:

- `PaginatedQuery`
    - builds the query (search, filters, sorting, pagination)
    - can return the raw paginator via `paginate()`
    - or return JSON API response via `toResponse()`

### Minimal Controller Example

[](#minimal-controller-example)

```
use AugmentMy\LaravelQueryPagination\PaginatedQuery;
use Illuminate\Http\Request;
use App\Models\User;

class UserController
{
    public function index(Request $request)
    {
        return PaginatedQuery::make(
            baseQuery: User::query(),
            searchable: ['name', 'email'],
            filterable: ['role', 'status'],
            sortable: ['name', 'created_at'],
            defaultSort: 'created_at',
            defaultSortDir: 'desc',
        )->toResponse($request);
    }
}
```

This is the cleanest form.
No need to manually call `PaginatedResponse`.

---

⚙️ Constructor Signature
------------------------

[](#️-constructor-signature)

```
PaginatedQuery::make(
    Builder $baseQuery,
    array $searchable = [],
    array $filterable = [],
    array $sortable = [],
    ?string $defaultSort = null,
    string $defaultSortDir = 'asc',
)
```

### Parameters

[](#parameters)

ParamDescription`baseQuery`Any Eloquent query builder (`User::query()`, etc.)`searchable`Columns used when `search=` is provided`filterable`Allowed filter fields (`filters[field]=value`)`sortable`Allowed columns for `sort_by``defaultSort`Fallback sort column`defaultSortDir``"asc"` or `"desc"`---

🔍 Supported Query Parameters
----------------------------

[](#-supported-query-parameters)

ParamExampleDescription`page``page=3`Page number (1‑based)`per_page``per_page=50`Items per page (clamped 1–100)`search``search=john`Searches all `$searchable` fields`filters[key]``filters[role]=admin`Per-field filters`sort_by``sort_by=name`Sorting field`sort_dir``sort_dir=desc`Sorting direction---

📦 JSON Response Format
----------------------

[](#-json-response-format)

All endpoints return:

```
{
  "data": [...],
  "meta": {
    "current_page": 1,
    "from": 1,
    "to": 25,
    "per_page": 25,
    "last_page": 6,
    "total": 143,
    "path": "https://api.example.com/api/users",
    "first_page_url": "...",
    "last_page_url": "...",
    "next_page_url": "...",
    "prev_page_url": null,
    "has_more_pages": true,
    "on_first_page": true
  }
}
```

These values come directly from Laravel’s `LengthAwarePaginator`.

---

🔧 Raw paginator access (optional)
---------------------------------

[](#-raw-paginator-access-optional)

If you ever need the paginator directly:

```
$paginator = PaginatedQuery::make(
    User::query(),
    searchable: ['name']
)->paginate($request);
```

You still get the `LengthAwarePaginator` object exactly as Laravel returns it.

---

🧪 Testing (for contributors)
----------------------------

[](#-testing-for-contributors)

This project uses **Orchestra Testbench** to bootstrap a minimal Laravel environment.

Run:

```
composer install
vendor/bin/phpunit
```

Tests use:

- In‑memory SQLite (`:memory:`)
- Temporary table creation
- Simple models to validate search/filter/sort/pagination

---

🗺️ Roadmap
----------

[](#️-roadmap)

- Range-based filtering (`from`, `to`)
- Relationship filters (`filters[role.name]`)
- Configurable operators
- Controller trait: `HasPaginatedIndex`
- Global config: max per\_page, default sorting rules

---

📄 License
---------

[](#-license)

MIT License. See `LICENSE` for details.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance70

Regular maintenance activity

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 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

Every ~1 days

Total

4

Last Release

169d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ab5ff37501e2e62108a086904b3ba94d8b7504cf9d06d16b562cfb1ba7ac0dd4?d=identicon)[Joshua-Augment](/maintainers/Joshua-Augment)

---

Top Contributors

[![Joshua-Augment](https://avatars.githubusercontent.com/u/101180253?v=4)](https://github.com/Joshua-Augment "Joshua-Augment (5 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/augmentmy-laravel-query-pagination/health.svg)

```
[![Health](https://phpackages.com/badges/augmentmy-laravel-query-pagination/health.svg)](https://phpackages.com/packages/augmentmy-laravel-query-pagination)
```

###  Alternatives

[yajra/laravel-datatables-oracle

jQuery DataTables API for Laravel

4.9k33.8M339](/packages/yajra-laravel-datatables-oracle)[spatie/laravel-enum

Laravel Enum support

3655.4M31](/packages/spatie-laravel-enum)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[aedart/athenaeum

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

255.2k](/packages/aedart-athenaeum)[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.

44643.1k1](/packages/pressbooks-pressbooks)[datomatic/nova-enum-field

A Laravel Nova PHP 8.1 enum field with filters

20134.2k](/packages/datomatic-nova-enum-field)

PHPackages © 2026

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