vice/laravel-fractal

Fractal helpers for Laravel 5
1,476 1
Install
composer require vice/laravel-fractal
Latest Version:v0.1.1
License:MIT
Last Updated:Mar 26, 2022
Links: GitHub  ·  Packagist
Maintainer: maxbrokman

Another Fractal Service Provider for Laravel 5 and Lumen

Latest Version on Packagist Build Status Software License

Fractal lets you present API data in a consistent way, by acting as an anti-corruption layer between your frontend and backend.

Read up on Fractal here.

Installation

Require this package

composer require vice/laravel-fractal

And then add the following to the service providers in app.php

Vice\LaravelFractal\FractalServiceProvider::class,

Usage

To send a JSON representation of a single entity to the frontend simply

public function show($id)
{
    //...

    fractalResponse()->item($thing, new ThingTransformer);
}

To send a JSON representation of a collection of entities to the frontend simply

public function index()
{
    //...

    fractalResponse()->collection($things, new ThingTransformer);
}

The collection method also supports paginators, and will automatically append their state under a meta key

If you need to transform data without immediately using it in a response you may inject Vice\LaravelFractal\FractalService into your controller / class and use it as so:

$json = $this->fractalService->item($thing, new ThingTransformer)->toJson();

Contributing

Please open any issues or pull requests on GitHub. This package is maintained by max.brokman@vice.com

For PRs please run the style fixer (vendor/bin/php-cs-fixer fix) before submitting.

Related Packages

gabrieloliverio/laravel5-generators

Database metadata-based generators for Laravel 5

1
erirk/paypalpayment

laravel-paypalpayment is simple package help you process direct credit card paym...

0
doctrine/dbal

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

631,580,251 9,707
laravel/framework

The Laravel Framework.

580,311,802 34,925
laravel/tinker

Powerful REPL for the Laravel framework.

489,754,436 7,444