pbmedia/fractal-illuminate-paginator

This package is abandoned and no longer maintained. No replacement package was suggested.

Bring back the Illuminate pagination results to your Fractal serializer

1.0.1 2016-08-02 09:35 UTC

This package is auto-updated.

Last update: 2020-09-12 13:16:36 UTC


README

Latest Version on Packagist Software License Build Status Quality Score Total Downloads

The Fractal package serializes the paginator different than the Illuminate paginator. This trait brings the serialization of the Illuminate paginator back to a Fractal serializer. Extend your serializer of choice, use this trait and you're done!

Installation

You can install the package via composer:

composer require pbmedia/fractal-illuminate-paginator

Usage

Create your own Serializer and use the trait from this package:

<?php

namespace Pbmedia\App\Serializers;

use League\Fractal\Serializer\DataArraySerializer as BaseSerializer;
use Pbmedia\Serializers\FractalIlluminatePaginatorTrait;

class DataArraySerializer extends BaseSerializer
{
    use FractalIlluminatePaginatorTrait;
}

Without the trait, the pagination results will be like this:

{
	data: [{
		id: 1,
		...
	}, {
		id: 2,
		...
	}, ...],
	meta: {
		pagination: {
			total: 33,
			count: 15,
			per_page: 15,
			current_page: 1,
			total_pages: 3,
			links: {
				next: "http://project.dev/api/v1/company?page=2"
			}
		}
	}
}

With the trait, the pagination results will be like this, just as you would convert a Illuminate\Pagination\LengthAwarePaginator to JSON.

{
	data: [{
		id: 1,
	  	...
	}, {
		id: 2,
	  	...
	}, ...],
	meta: {
		pagination: {
			total: 33,
			per_page: 15,
			current_page: 1,
			last_page: 3,
			next_page_url: "http://project.dev/api/v1/company?page=2",
			prev_page_url: null,
			from: 1,
			to: 15
		}
	}
}

Security

If you discover any security related issues, please email pascal@pascalbaljetmedia.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.