bastian / fractal-magic
There is no license information available for the latest version (0.2) of this package.
A nice wrapper for the league's fractal package.
0.2
2014-03-01 15:42 UTC
Requires
- illuminate/support: 4.2.*@dev
- league/fractal: 0.7.*
- symfony/http-foundation: 2.4.*
Requires (Dev)
- phpspec/phpspec: 2.0.*@dev
This package is not auto-updated.
Last update: 2025-02-25 07:59:13 UTC
README
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.
Installation
Add this to your composer.json
require:
"bastian/fractal-magic": "dev-master"
and run composer update
.
Usage
$fractal = new Hofmann\FractalMagic\Fractal([ 'posts' => new ResourceTransformer ]); // Singular for a fractal item $fractal->post(['title' => 'Hello']); // Plural for a fractal collection $fractal->posts([ ['title' => 'Hi!'] ]);
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:
Response::macro('fractal', function() { return new Hofmann\FractalMagic\Fractal([ 'resource' => new ResourceTransformer ]); });
Now you can use this in your controller:
class SomeController { public function index() { return Response::fractal()->resources($data); } }