This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Fast Paginate is a Laravel package that provides an optimized limit/offset pagination method using a "deferred join" technique. Instead of fetching full rows during pagination, it first retrieves only primary keys in an optimized subquery, then fetches full records for those specific IDs. This significantly improves performance on large datasets.
Run all tests:
./vendor/bin/phpunitRun a specific test file:
./vendor/bin/phpunit tests/Integration/BuilderTest.phpRun a specific test method:
./vendor/bin/phpunit --filter basic_testNote: Tests require a MySQL database (8.4+). Configure via environment variables or phpunit.xml:
- DB_DATABASE=fast_paginate
- DB_USERNAME=test
- DB_PASSWORD=root
The package registers macros on Laravel's Eloquent Builder and Relation classes via FastPaginateProvider:
-
FastPaginate(src/FastPaginate.php): Core pagination logic. ImplementsfastPaginate()andsimpleFastPaginate()methods that:- Clone the query and select only primary keys
- Run pagination on the key-only query
- Use the retrieved IDs in a
WHERE INclause on the original query - Return full records with proper pagination metadata
-
BuilderMixin(src/BuilderMixin.php): AddsfastPaginate()andsimpleFastPaginate()methods to Eloquent Builder -
RelationMixin(src/RelationMixin.php): Adds the same methods to Eloquent Relations, with special handling forBelongsToManyandHasManyThrough -
ScoutMixin(src/ScoutMixin.php): ProvidesfastPaginate()on Laravel Scout builders (defers to standard pagination as Scout already optimizes)
The package automatically falls back to standard pagination when:
- Query contains
havings,groups, orunions perPageis set to-1(get all records)- Query contains incompatible expressions (detected via
QueryIncompatibleWithFastPagination)
Order-by columns that reference computed/aliased columns are preserved in the inner query to maintain correct ordering during the key-selection phase.