2017 © Pedro Peláez
 

library fractal-magic

A nice wrapper for the league's fractal package.

image

bastian/fractal-magic

A nice wrapper for the league's fractal package.

  • Sunday, September 28, 2014
  • by BastianHofmann
  • Repository
  • 1 Watchers
  • 3 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Fractal Wrapper

Build Status, (*1)

This package puts a nice wrapper around the fractal package: http://fractal.thephpleague.com. It handles the nitty gritty task of spinning up the manager, creating a resource and provides a convient location to register your transformers., (*2)

Installation

Add this to your composer.json require:, (*3)

"bastian/fractal-magic": "dev-master"

and run composer update., (*4)

Usage

``` php $fractal = new Hofmann\FractalMagic\Fractal([ 'posts' => new ResourceTransformer ]);, (*5)

// Singular for a fractal item, (*6)

$fractal->post(['title' => 'Hello']);, (*7)

// Plural for a fractal collection, (*8)

$fractal->posts([ ['title' => 'Hi!'] ]);, (*9)


Notice that you only have to set the singular resource binding. This will return a Symfony response with the data in place, which you can return from your controller or route closure. ## Laravel Usage For usage in laravel I suggest you register a `Response::macro` like this: ``` php Response::macro('fractal', function() { return new Hofmann\FractalMagic\Fractal([ 'resource' => new ResourceTransformer ]); });

Now you can use this in your controller:, (*10)

``` php class SomeController {, (*11)

public function index() { return Response::fractal()->resources($data); }, (*12)

} ```, (*13)

The Versions

28/09 2014

dev-master

9999999-dev

A nice wrapper for the league's fractal package.

  Sources   Download

The Requires

 

The Development Requires

01/03 2014

0.2

0.2.0.0

A nice wrapper for the league's fractal package.

  Sources   Download

The Requires

 

The Development Requires

27/02 2014

0.1

0.1.0.0

A nice wrapper for the league's fractal package.

  Sources   Download

The Requires

 

The Development Requires