Download the PHP package austinw/laravel-union-paginator without Composer

On this page you can find all versions of the php package austinw/laravel-union-paginator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-union-paginator

Laravel Union Paginator

Tests Static Analysis Total Downloads Latest Stable Version License

Paginate several Eloquent models as one list — an activity feed of posts, comments and users, for example — with a single SQL UNION, and get the models back in order.

Installation

Requires PHP 8.2+ and Laravel 12 or 13. Upgrading from 2.x? See the migration guide.

How it works

  1. Each model becomes one SELECT of four columns: id (the primary key), created_at, updated_at and type (the model's class name). Global scopes and soft deletes apply.
  2. The selects are combined with UNION and wrapped in a derived table, union_paginator.
  3. Your where and orderBy calls run on that derived table, so they apply to every model.
  4. The page of rows is turned back into models with one findMany() per model type.

Filtering and ordering the whole union

Query builder where* and orderBy* methods, latest(), oldest(), reorder() and inRandomOrder() are forwarded to the union. They can only see the union's columns (id, created_at, updated_at, type, plus any you select).

When you order, type and id are appended as tie-breakers so pages stay stable when sort values are equal. Without an order, the database decides the row order — add one if the order matters.

Calls can come in any order: the query is built when you paginate. when() and unless() receive the paginator:

where(fn ($query) => ...) closures receive a plain query builder for the derived table, not an Eloquent builder.

Constraining one model

Use applyScope() for conditions on a single model, including relationship queries such as whereHas():

The callback receives that model's Eloquent builder. Call applyScope() more than once to add more conditions.

Pagination styles

Cursor pagination needs column orders on non-null columns. type and id are appended automatically, so ->latest()->cursorPaginate() works as long as created_at is never null. Raw (orderByRaw), random and expression orders throw, because Laravel cannot build a cursor from them.

Loading models

By default each page runs one findMany() per model type. To eager load or customise the query, use fetchModelsUsing():

The callback receives the keys on the current page and returns the models. Rows whose model is not returned (for example, deleted between the two queries) are left out of the page.

Raw rows

Skip model loading and get the union rows (stdClass) instead:

Transforming results

The callback receives the model, or the raw row when model retrieval is prevented. A later call for the same model replaces the earlier one.

Custom columns

Replace a model's default select with setSelectedColumns(). Columns in a UNION are matched by position, so every model must select the same number of columns in the same order. Alias the key as id. The paginator always adds type as the last column.

Models without timestamp columns should set const CREATED_AT = null; and const UPDATED_AT = null; — the paginator then selects NULL for them.

Limitations

Testing

CI runs the suite on PHP 8.2–8.5 with Laravel 12 and 13 on SQLite, plus MySQL 8.4 and Postgres 17.

License

MIT. See LICENSE.md.


All versions of laravel-union-paginator with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/contracts Version ^12.0|^13.0
illuminate/database Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.0
illuminate/pagination Version ^12.0|^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package austinw/laravel-union-paginator contains the following files

Loading the files please wait ...