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 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

Technical Evaluation

Architecture Fit

  • Pros:

    • Lightweight & Decoupled: The package follows a callback-driven design, making it agnostic to data sources (arrays, databases, APIs, etc.). This aligns well with Laravel’s modularity and dependency injection principles.
    • Flexible Metadata Handling: Supports arbitrary metadata injection, useful for enriching pagination responses (e.g., search aggregations, caching hints).
    • Iterator/Generator Support: Allows lazy-loading of paginated results, reducing memory overhead for large datasets (critical for Laravel APIs or admin panels).
    • No Laravel-Specific Dependencies: Pure PHP, ensuring compatibility with any Laravel project without coupling to Laravel’s Eloquent or Query Builder.
  • Cons:

    • Outdated (2019): No active maintenance or Laravel 10+ compatibility guarantees. Risk of deprecated PHP/MySQL functions (e.g., mysql_*).
    • Manual Query Handling: Requires manual SQL LIMIT/OFFSET logic (no built-in Eloquent integration), increasing boilerplate for database-backed pagination.
    • Limited Built-in Features: Lacks advanced features like windowed pagination (e.g., cursor-based), infinite scroll, or server-side rendering hooks.

Integration Feasibility

  • Database Integration:

    • Feasible but Manual: Works with raw PDO/DBAL queries or Eloquent’s get() with LIMIT/OFFSET, but requires custom query logic. Example:
      $paginator->setSliceCallback(function ($offset, $length) {
          return User::query()->offset($offset)->limit($length)->get();
      });
      
    • Risk: Performance degradation with deep offsets (e.g., OFFSET 10000), common in large datasets.
  • API/Collection Integration:

    • Ideal for Non-DB Data: Perfect for paginating API responses, Elasticsearch results, or in-memory collections (e.g., caching layers).
    • Example:
      $paginator->setSliceCallback(function ($offset, $length) use ($apiClient) {
          return $apiClient->getItems($offset, $length);
      });
      
  • View Layer:

    • Template-Friendly: Returns structured metadata (e.g., getPages(), getNextPageNumber()) for easy Blade template integration.
    • Iterator Support: Enables foreach ($pagination as $item) loops directly in views.

Technical Risk

  • Deprecation Risk:
    • Uses mysql_* functions (deprecated since PHP 5.5). Requires refactoring to PDO/DBAL.
    • No Laravel 10+ compatibility testing (e.g., PHP 8.2+ features like named arguments).
  • Performance:
    • OFFSET-based pagination can be slow for large datasets. Mitigation: Use window functions (Laravel 8+) or cursor-based pagination.
  • Testing:
    • No PHPUnit tests or Laravel-specific test cases. Requires custom test coverage for edge cases (e.g., empty pages, metadata handling).

Key Questions

  1. Data Source Compatibility:

    • Will this replace Laravel’s built-in pagination (Illuminate\Pagination) or supplement it? (e.g., for non-DB collections).
    • How will we handle database pagination performance at scale (e.g., 1M+ records)?
  2. Maintenance:

    • Should we fork the package to modernize it (e.g., add Laravel 10 support, replace mysql_* with PDO)?
    • What’s the fallback if the package breaks (e.g., switch to Illuminate\Pagination or spatie/laravel-pagination)?
  3. Feature Gaps:

    • Do we need advanced features (e.g., infinite scroll, multi-level pagination) not covered by this package?
    • How will we handle edge cases like dynamic itemsPerPage or client-side filtering?
  4. Testing Strategy:

    • How will we test pagination with large datasets without hitting performance bottlenecks?
    • Should we mock the callbacks in unit tests or use a real database?

Integration Approach

Stack Fit

  • Laravel Ecosystem:

    • Pros:
      • Works alongside Laravel’s existing pagination (Illuminate\Pagination) without conflicts.
      • Can be used for non-DB collections (e.g., API responses, cached data) where Eloquent pagination isn’t applicable.
    • Cons:
      • No Eloquent Integration: Requires manual query building (e.g., Model::query()->offset()->limit()), unlike Illuminate\Pagination which integrates with Eloquent’s query builder.
      • Duplicate Logic: If using both packages, pagination logic (e.g., OFFSET/LIMIT) may need to be maintained in two places.
  • Alternative Use Cases:

    • Admin Panels: Paginate complex query results (e.g., multi-table joins) not easily handled by Eloquent.
    • Legacy Systems: Integrate with existing codebases using raw SQL or arrays.
    • Microservices: Paginate API responses or external data sources.

Migration Path

  1. Assessment Phase:

    • Audit current pagination usage (e.g., Illuminate\Pagination, custom solutions).
    • Identify use cases where this package adds value (e.g., non-DB collections, metadata enrichment).
  2. Pilot Integration:

    • Start with a single endpoint/view using the package (e.g., a non-DB collection).
    • Example:
      // 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'));
      
  3. Gradual Replacement:

    • Replace custom pagination logic with this package where applicable.
    • For database pagination, wrap Eloquent queries in callbacks:
      $paginator->setSliceCallback(function ($offset, $length) {
          return User::query()
              ->where('active', true)
              ->offset($offset)
              ->limit($length)
              ->get();
      });
      
  4. Fallback Strategy:

    • If issues arise (e.g., performance), revert to Illuminate\Pagination or spatie/laravel-pagination.

Compatibility

  • PHP Version: Tested on PHP 7.2–7.4 (Laravel 7–9). May need updates for PHP 8.2+ (e.g., named arguments, strict types).
  • Laravel Version: No official support, but likely works with Laravel 7–9. Test with Laravel 10+ if adopting.
  • Database: Supports any PDO-compatible database (MySQL, PostgreSQL, SQLite). Avoid mysql_* functions.
  • Dependencies: None (pure PHP), but requires Composer.

Sequencing

  1. Phase 1: Non-DB Collections
    • Use for API responses, cached data, or in-memory collections (low risk).
  2. Phase 2: Database Pagination
    • Replace custom OFFSET/LIMIT logic with this package (moderate risk).
  3. Phase 3: Advanced Features
    • Extend with custom metadata or callbacks (e.g., caching, analytics).
  4. Phase 4: Performance Optimization
    • Address OFFSET issues with window functions or cursor-based pagination.

Operational Impact

Maintenance

  • Pros:
    • Minimal Boilerplate: Callbacks encapsulate pagination logic, reducing code duplication.
    • Metadata Flexibility: Easy to extend with custom data (e.g., caching metadata).
  • Cons:
    • No Active Maintenance: Requires vigilance for PHP/Laravel updates.
    • Callback Complexity: Debugging issues in callbacks (e.g., SQL errors) may be harder than with Eloquent.
  • Mitigations:
    • Fork the Package: Update to modern PHP/Laravel standards if critical.
    • Document Callbacks: Clearly document callback logic for future maintainers.

Support

  • Pros:
    • Simple API: Easy to onboard developers familiar with Laravel.
    • No Laravel-Specific Issues: Pure PHP reduces Laravel-specific support overhead.
  • Cons:
    • Limited Community: No active GitHub issues or Stack Overflow tags.
    • Undocumented Edge Cases: May need to build internal docs for complex scenarios (e.g., dynamic itemsPerPage).
  • Support Plan:
    • Create internal runbooks for common issues (e.g., empty pages, metadata handling).
    • Monitor for Laravel/PHP deprecations affecting the package.

Scaling

  • Performance:
    • Strengths:
      • Iterator/generator support reduces memory usage for large datasets.
      • Callback-based design allows optimization per data source (e.g., cursor-based for databases).
    • Weaknesses:
      • OFFSET-based pagination performs poorly at scale (e.g., OFFSET 100000).
      • No built-in connection pooling or query caching.
    • Mitigations:
      • Use window functions (L
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.
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
spatie/mailcoach-vapor