LaravelPackages.net
Acme Inc.
Toggle sidebar
bertbijnens/laravel-fractal-paginate

Extending Spatie's laravel fractal package to support build-in pagination

17.200
2
v1.2.4
About bertbijnens/laravel-fractal-paginate

bertbijnens/laravel-fractal-paginate is a Laravel package for extending spatie's laravel fractal package to support build-in pagination. It currently has 2 GitHub stars and 17.200 downloads on Packagist (latest version v1.2.4). Install it with composer require bertbijnens/laravel-fractal-paginate. Discover more Laravel packages by bertbijnens or browse all Laravel packages to compare alternatives.

Last updated

Laravel fractal paginate

This package provides macro functions to easily implement pagination. Spatie's Laravel fractal wrapper is required.

Install

This packages implements Laravel auto-discovery. Installing this package using composer:

composer require bertbijnens/laravel-fractal-paginate

Usage

Use the "paginate" macro on fractal:

return fractal()->paginate($query, $transformer);

The paginate macro acts the same as the collection method. However instead of a collection it expects a queryable object.

Based on the available request variables it will apply pagination with support for:

  • page (starts at 1)
  • offset
  • limit (currently capped at 100)
  • since (filter objects updated since this timestamp)
  • until (filter objects updated until this timestamp)

The response will look something like:

{
	data: [
		{},
		{},
		{},
		....
	],
	links: {
		next: 'https://.....?page=2&limit=5'
	}
}

The response always returns the next url, when there is no more data available this will be null.

Optional pagination

You can set the pagination response as optional

return fractal()->paginate($query, $transformer, false);

When this third parameters (paginationRequired, default true) is set to false and there are no pagination parameters in the request, the reponse will go through the default serializer as set in the fractal config.

Star History Chart