krossroad/laravel-union-paginator

Package to support pagination in union queries in Laravel Eloquent.

v5.5.5 2018-10-02 07:33 UTC

This package is auto-updated.

Last update: 2024-11-09 20:01:54 UTC


README

Latest Stable Version Total Downloads License

Note

Laravel supports union pagination from v5.7

Installation

For Laravel v5.5 to v5.7

composer require 'krossroad/laravel-union-paginator:5.5'

For Laravel v5.2 to v5.4

composer require 'krossroad/laravel-union-paginator:5.4'

Usage

Just use UnionPaginatorTrait in your model and you are good to go.

Example Model

<?php
/**
 * @filename {project}/App/Models/User.php
 */

namespace \App\Models\User;

use Krossroad\UnionPaginator\UnionPaginatorTrait;

class User extends Model
{
    use UnionPaginatorTrait;
    ...
}

Example usage somewhere in application code

->unionPaginate() --> returns \Illuminate\Pagination\LengthAwarePaginator instance

$first = User::whereNull('first_name');

$pagination = User::whereNull('last_name')
    ->union($first)
    ->unionPaginate(
        $perPage,
        $columns,
        $pageName = 'page',
        $page
    );
    

If you find any bug, issue or have queries. Please create a new issue