joshbrw/laravel-pagination-specification

A package for consistent pagination in Laravel.
3,032 1
Install
composer require joshbrw/laravel-pagination-specification
Latest Version:v0.1.9
PHP:^7
Laravel:5
License:MIT
Last Updated:Jan 29, 2018
Links: GitHub  ·  Packagist
Maintainer: joshbrw

Laravel Pagination Specification

The main purpose of this package is to provide a consistent object that represents all of the main values you have to take into account when paginating (i.e. Current Page, Per Page, Appends for the URLs).

This object can then be passed around to methods and used for less verbose method parameters.

Installing

  1. composer require joshbrw/laravel-pagination-specification
  2. Add the following Service Provider to your config/app.php under provider:
       Joshbrw\PaginationSpecification\PaginationSpecificationServiceProvider::class
    
  3. Optionally publish the config and change the default Per Page;
    php artisan vendor:publish --provider="Joshbrw\PaginationSpecification\PaginationSpecificationServiceProvider"
    

Usage

The class is bound into the container under the Joshbrw\PaginationSpecification\PaginationSpecification interface, and can be overwritten/decorated if required.

For example, injecting into a Controller method:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\View\View;
use Joshbrw\PaginationSpecification\PaginationSpecification;

class UserController extends Controller {
    public function index(
        Request $request,
        PaginationSpecification $paginationSpecification,
        UserRepository $userRepository
    ): View {
        // Reads the `per_page` and `page` values from the request
        $paginationSpecification->fromRequest($request);
        
        // Set how many items we want per page
        $paginationSpecification->setPerPage(30);
        
        // This can now be passed around to other methods, which can typehint it as a dependency
        return $userRepository->get($paginationSpecification);
    }
}

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

644,549,754 9,698
laravel/framework

The Laravel Framework.

593,882,149 34,959
laravel/tinker

Powerful REPL for the Laravel framework.

507,193,856 7,441
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

423,477,751 607
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

399,241,428 4,660

Version History

Version Released PHP Laravel License
v0.1.9 ^7 5.4.*|5.5.* MIT
v0.1.8 ^7 5.4.*|5.5.* MIT
v0.1.7 ^7 5.4.*|5.5.* MIT
v0.1.6 ^7 5.4.*|5.5.* MIT
v0.1.5 ^7 5.4.*|5.5.* MIT