PHPackages                             companue/auto-paginate - 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. [API Development](/categories/api)
4. /
5. companue/auto-paginate

ActiveLibrary[API Development](/categories/api)

companue/auto-paginate
======================

Laravel package for automatic API pagination with infinite scroll support. Provides reusable traits and helpers for consistent paginated responses across all API endpoints.

1.0.1(4mo ago)041MITPHPPHP ^8.1

Since Dec 12Pushed 4mo agoCompare

[ Source](https://github.com/companue/auto-pagination)[ Packagist](https://packagist.org/packages/companue/auto-paginate)[ Docs](https://github.com/companue/auto-paginate)[ RSS](/packages/companue-auto-paginate/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (3)Used By (1)

Companue Auto-Paginate
======================

[](#companue-auto-paginate)

[![Latest Version on Packagist](https://camo.githubusercontent.com/427dc1be8918f7f946b683a2d2c8ee2f93c7c3ce3c61d585f43c02a23710ac0d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f6d70616e75652f6175746f2d706167696e6174652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/companue/auto-paginate)[![Total Downloads](https://camo.githubusercontent.com/c124bb5e89cdca3eee8ea6510366e5af29fc833f230925902cfe6fc86f82f683/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f6d70616e75652f6175746f2d706167696e6174652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/companue/auto-paginate)

A Laravel package that provides automatic API pagination with infinite scroll support. Add pagination to any controller endpoint with just one line of code!

Features
--------

[](#features)

- ✅ **One-Line Integration** - Add pagination with a single method call
- ✅ **Automatic Scroll Detection** - Perfect for infinite scroll UIs
- ✅ **Consistent Response Format** - Standardized across all endpoints
- ✅ **Backward Compatible** - Supports both paginated and non-paginated responses
- ✅ **Flexible** - Works with Query Builders and Collections
- ✅ **Type Safe** - Full PHP type hints and return types
- ✅ **Zero Configuration** - Works out of the box

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

[](#installation)

Install via Composer:

```
composer require companue/auto-paginate
```

The package will automatically register its service provider.

### Quick Installation

[](#quick-installation)

Run the installation command for an interactive setup:

```
php artisan auto-paginate:install
```

This will guide you through two installation options:

1. **Publish AutoPaginatedController** (Recommended) - Extend your controllers from it
2. **Update base Controller.php** - Inject trait directly into the base controller

### Manual Installation Options

[](#manual-installation-options)

#### Option 1: Publish AutoPaginatedController (Recommended)

[](#option-1-publish-autopaginatedcontroller-recommended)

Publish the AutoPaginatedController to your project:

```
php artisan vendor:publish --tag=auto-paginate-controller
```

Or use the command with the default option:

```
php artisan auto-paginate:install
```

This creates `app/Http/Controllers/API/AutoPaginatedController.php` with pagination methods built-in.

Then update your API controllers to extend it:

```
use App\Http\Controllers\API\AutoPaginatedController;

class YourController extends AutoPaginatedController
{
    public function index(Request $request)
    {
        $query = YourModel::query();
        return response()->json(
            $this->indexResponse($query, YourResource::class, $request)
        );
    }
}
```

### Alternative: Use Trait Directly

[](#alternative-use-trait-directly)

If you prefer not to use AutoPaginatedController, add the trait to your controllers:

```
use Companue\AutoPaginate\Traits\PaginatesQueries;

class YourController extends Controller
{
    use PaginatesQueries;

    // Same usage as above
}
```

#### Option 2: Update Base Controller (Direct Injection)

[](#option-2-update-base-controller-direct-injection)

Inject the trait directly into your base `Controller.php`:

```
php artisan auto-paginate:install --base-controller
```

This will:

- Create a backup of your `Controller.php` at `app/Http/Controllers/Controller.php.backup`
- Add `use Companue\AutoPaginate\Traits\PaginatesQueries;` import statement
- Add `PaginatesQueries` to your existing trait list in the Controller class

**Before:**

```
