ashleydawson/simple-pagination
Framework-agnostic pagination library for PHP. Provide callbacks to count total items and fetch a slice (offset/length), and it returns a Pagination object with items plus page metadata and ranges. Works with arrays, DB lists, Doctrine, Solr, and more.
Pros:
Cons:
mysql_*).LIMIT/OFFSET logic (no built-in Eloquent integration), increasing boilerplate for database-backed pagination.cursor-based), infinite scroll, or server-side rendering hooks.Database Integration:
get() with LIMIT/OFFSET, but requires custom query logic. Example:
$paginator->setSliceCallback(function ($offset, $length) {
return User::query()->offset($offset)->limit($length)->get();
});
OFFSET 10000), common in large datasets.API/Collection Integration:
$paginator->setSliceCallback(function ($offset, $length) use ($apiClient) {
return $apiClient->getItems($offset, $length);
});
View Layer:
getPages(), getNextPageNumber()) for easy Blade template integration.foreach ($pagination as $item) loops directly in views.mysql_* functions (deprecated since PHP 5.5). Requires refactoring to PDO/DBAL.OFFSET-based pagination can be slow for large datasets. Mitigation: Use window functions (Laravel 8+) or cursor-based pagination.Data Source Compatibility:
Illuminate\Pagination) or supplement it? (e.g., for non-DB collections).Maintenance:
mysql_* with PDO)?Illuminate\Pagination or spatie/laravel-pagination)?Feature Gaps:
itemsPerPage or client-side filtering?Testing Strategy:
Laravel Ecosystem:
Illuminate\Pagination) without conflicts.Model::query()->offset()->limit()), unlike Illuminate\Pagination which integrates with Eloquent’s query builder.OFFSET/LIMIT) may need to be maintained in two places.Alternative Use Cases:
Assessment Phase:
Illuminate\Pagination, custom solutions).Pilot Integration:
// In a controller
$paginator = new Paginator();
$paginator->setItemsPerPage(20);
$paginator->setItemTotalCallback(fn() => Cache::get('total_items'));
$paginator->setSliceCallback(fn($offset, $length) => Cache::get("items_{$offset}_{$length}"));
$pagination = $paginator->paginate(request('page'));
return view('results', compact('pagination'));
Gradual Replacement:
$paginator->setSliceCallback(function ($offset, $length) {
return User::query()
->where('active', true)
->offset($offset)
->limit($length)
->get();
});
Fallback Strategy:
Illuminate\Pagination or spatie/laravel-pagination.mysql_* functions.OFFSET/LIMIT logic with this package (moderate risk).OFFSET issues with window functions or cursor-based pagination.itemsPerPage).OFFSET-based pagination performs poorly at scale (e.g., OFFSET 100000).How can I help you explore Laravel packages today?