Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Simple Pagination

Simple Pagination Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Simple pagination library for PHP implements a paging interface on collections of things.

Frequently asked questions about Simple Pagination
Can I use this package for Laravel database pagination instead of Illuminate\Pagination?
Yes, but with manual setup. Unlike Laravel’s built-in pagination, this package requires you to handle SQL `OFFSET`/`LIMIT` logic yourself (e.g., `Model::query()->offset($offset)->limit($length)->get()`). It’s ideal for supplementing Laravel’s pagination when you need framework-agnostic control, like for non-DB collections or APIs.
Will this work with Laravel 10 and PHP 8.2+?
No, this package was last updated in 2019 and lacks official Laravel 10 or PHP 8.2 support. It may work with minor tweaks, but you’ll need to manually refactor deprecated functions (e.g., `mysql_*`) to PDO or modern alternatives. Test thoroughly before production use.
How do I paginate API responses or Elasticsearch results with this package?
Use the `setSliceCallback` and `setItemTotalCallback` methods to wrap API calls or Elasticsearch queries. For example, pass a callback like `function($offset, $length) { return $apiClient->fetch($offset, $length); }`. The package handles the pagination logic while you manage the data source.
Is this package memory-efficient for large datasets?
Yes, it supports iterators/generators for lazy-loading paginated results, reducing memory overhead. However, database pagination with deep `OFFSET` values (e.g., `OFFSET 10000`) can still be slow. For large datasets, consider window functions or cursor-based pagination instead.
How do I integrate this with Laravel Blade templates?
The `Pagination` object includes methods like `getPages()`, `getNextPageNumber()`, and `getItems()` to render pagination controls. Loop through items with `foreach ($pagination as $item)` or manually build links using the metadata. It’s template-friendly but lacks Laravel’s built-in pagination views.
What if I need advanced features like infinite scroll or windowed pagination?
This package doesn’t support infinite scroll or cursor-based pagination out of the box. For those features, consider alternatives like `spatie/laravel-pagination` or Laravel’s built-in `Illuminate\Pagination` with custom windowing logic. This package focuses on simplicity and basic offset/length pagination.
How do I test this package in Laravel?
Since there are no built-in tests, mock the callbacks in PHPUnit using `createMock()` or test doubles. For database tests, use in-memory SQLite or seed small datasets to avoid performance bottlenecks. Focus on edge cases like empty pages, metadata accuracy, and callback failures.
Can I use this alongside Laravel’s Eloquent pagination?
Yes, but you’ll duplicate pagination logic (e.g., `OFFSET`/`LIMIT`). Use this package for non-DB collections (e.g., APIs, cached data) and Laravel’s pagination for Eloquent models. Alternatively, fork the package to add Eloquent integration if needed.
What are the risks of using deprecated PHP functions like `mysql_*` in this package?
The package uses deprecated `mysql_*` functions, which may fail in PHP 7.4+. Replace them with PDO or Laravel’s Query Builder before use. If you’re unsure, audit the codebase or fork the package to modernize it for Laravel 10+ compatibility.
How do I handle dynamic items per page or client-side filtering?
This package doesn’t natively support dynamic `itemsPerPage` or client-side filtering. Override the `setItemsPerPage()` method or extend the `Pagination` class to add custom logic. For filtering, pre-process data before passing it to the callbacks or use middleware to modify the slice callback dynamically.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky