spiral/pagination
Spiral Pagination Toolkit provides lightweight, framework-agnostic pagination primitives for PHP apps. Build and pass around page limits/offsets and related metadata cleanly, with strong type safety, tests, and Psalm support.
Pros:
Cons:
PageInterface, PaginatorInterface, CursorPaginatorInterface), requiring additional libraries (e.g., spiral/database, laravel/framework) or custom code to fulfill pagination logic. This increases boilerplate and development time for basic use cases.->links(), ->appends(), LengthAwarePaginator), forcing manual implementation of common functionality.Laravel Compatibility:
PageInterface to standardize API responses (e.g., data, meta.pagination) across frontend and backend.CursorPaginatorInterface for GraphQL or cursor-based APIs (e.g., Relay-style pagination).Illuminate\Pagination\AbstractPaginator already provides similar interfaces, making this package redundant unless extending functionality (e.g., adding cursor support to offset pagination).spiral/database or custom Eloquent queries). Example:
use Spiral\Pagination\CursorPaginatorInterface;
use Illuminate\Database\Eloquent\Builder;
class EloquentCursorPaginator implements CursorPaginatorInterface {
public function getItems(): array { ... }
public function getCursor(): string { ... }
public function getNextCursor(): ?string { ... }
// ...
}
Non-Database Use Cases:
use Spiral\Pagination\PageInterface;
class ApiResponsePaginator implements PageInterface {
public function __construct(private array $data, private int $total) {}
public function getItems(): array { return $this->data; }
public function getTotal(): int { return $this->total; }
// ...
}
Technical Debt:
->links() or ->appends() require custom implementation, increasing development time.LaravelPaginatorToSpiralPageAdapter).spatie/laravel-pagination?
spatie/laravel-pagination is actively maintained and Laravel-specific, while this package is lightweight but unmaintained.data, meta.pagination) for consistency across clients (React, mobile, etc.).PageInterface in gRPC or REST APIs).Illuminate\Pagination for simple use cases (e.g., admin tables).LIMIT/OFFSET).Assessment Phase:
->paginate(10), ->simplePaginate() in controllers).Pilot Integration:
PageInterface for a non-critical API endpoint or admin panel.PageInterface:
use Spiral\Pagination\PageInterface;
class ApiPaginator implements PageInterface {
public function __construct(
private array $items,
private int $total,
private int $perPage,
private int $currentPage
) {}
public function getItems(): array { return $this->items; }
public function getTotal(): int { return $this->total; }
public function getPage(): int { return $this->currentPage; }
public function getPerPage(): int { return $this->perPage; }
}
Gradual Rollout:
PageInterface for new APIs or features.use Spiral\Pagination\PageInterface;
use Illuminate\Pagination\LengthAwarePaginator;
class LaravelPageAdapter implements PageInterface {
public function __construct(private LengthAwarePaginator $paginator) {}
public function getItems(): array { return $this->paginator->items(); }
public function getTotal(): int { return $this->paginator->total(); }
public function getPage(): int { return $this->paginator
How can I help you explore Laravel packages today?