2017 © Pedro Peláez
 

library laravel5-fractal

A simple fractal service provider and transformer generator with model attributes for laravel 5.

image

cyvelnet/laravel5-fractal

A simple fractal service provider and transformer generator with model attributes for laravel 5.

  • Wednesday, October 11, 2017
  • by cyvelnet
  • Repository
  • 7 Watchers
  • 78 Stars
  • 58,003 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 19 Forks
  • 1 Open issues
  • 31 Versions
  • 8 % Grown

The README.md

StyleCI Build Status Total Downloads Latest Stable Version Latest Unstable Version License, (*1)

laravel5-fractal

A simple fractal service provider and transformer generator for laravel 5 and lumen, (*2)

Installation

Laravel

Require this package with composer using the following command:, (*3)

composer require cyvelnet/laravel5-fractal

After updating composer, add the ServiceProvider to the providers array in config/app.php, (*4)

Cyvelnet\Laravel5Fractal\Laravel5FractalServiceProvider::class,

and register Facade And optionally add a new line to the aliases array:, (*5)

'Fractal' => Cyvelnet\Laravel5Fractal\Facades\Fractal::class, (*6)

Lumen

register service provider in /bootstrap/app.php for lumen, (*7)

$app->register(Cyvelnet\Laravel5Fractal\Laravel5FractalServiceProvider::class);

and uncomment the line, (*8)

$app->withFacades();

and finally register Facade with, (*9)

class_alias(Cyvelnet\Laravel5Fractal\Facades\Fractal::class, 'Fractal');

Config

You can also publish the config file to change implementations to suits you., (*10)

php artisan vendor:publish --provider="Cyvelnet\Laravel5Fractal\Laravel5FractalServiceProvider"
Automatic sub resources injection.

Auto inject/embed sub resources are disabled by default, to enable this feature, edit config/fractal.php and set, (*11)

autoload => true, (*12)

Command

cyvelnet/fractal come with a helpful commandline to assist your api transformation, just type and your Eloquent model attributes will be added to your transform array automatically, (*13)

 // generate a empty transformer
 php artisan make:transformer UserTransformer

 // generate a modeled transformer
 php artisan make:transformer UserTransformer -m User

Usage

Fractal::item();

Transform a single record, (*14)


$user = User::find(1); Fractal::item($user, new UserTransformer());

Fractal::collection();

Transform a collection of records, (*15)


$users = User::where('activated', true)->get(); // $resourceKey is optional for most serializer, but recommended to set for JsonApiSerializer $resourceKey = 'user'; Fractal::collection($users, new UserTransformer(), $resourceKey);

Fractal::includes()

Inject sub resources, (*16)


Fractal::includes('orders') // where 'orders' is defined in your transformer class's $availableIncludes array

Fractal::excludes()

Remove sub resources, (*17)


Fractal::excludes('orders')

Fractal::setSerializer()

Change transformer serializer, (*18)


Fractal::setSerializer(\Acme\MySerializer); // where MySerializer is a class extends \League\Fractal\Serializer\SerializerAbstract

Fractal::fieldsets()

add sparse fieldset, (*19)


Fractal::fieldsets(['orders' => 'item,qty,total,date_order'])

Fractal::addMeta()

add extra meta data to root, (*20)


// specify with single meta data Fractal::addMeta($key = 'metaKey', $data = 'metaData') // add an array of meta data Fractal::addMeta([ 'key1' => 'data1', 'key2' => 'data2' ])

Trait

https://github.com/Cyvelnet/laravel5-fractal/wiki/Transformable-Trait, (*21)

Sub Relationship Modifier

https://github.com/Cyvelnet/laravel5-fractal/wiki/Sub-Relationship-Modifier, (*22)

Extra

https://github.com/Cyvelnet/laravel5-fractal/wiki/Custom-TransformerableAbstract-class, (*23)

The Versions

11/10 2017

dev-master

9999999-dev

A simple fractal service provider and transformer generator with model attributes for laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar cyvelnet

api laravel5 fractal transformer api transformer

11/10 2017

v2.2.1

2.2.1.0

A simple fractal service provider and transformer generator with model attributes for laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar cyvelnet

api laravel5 fractal transformer

23/08 2017

2.1.x-dev

2.1.9999999.9999999-dev

A simple fractal service provider and transformer generator with model attributes for laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar cyvelnet

api laravel5 fractal transformer

23/08 2017

v2.2.0

2.2.0.0

A simple fractal service provider and transformer generator with model attributes for laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar cyvelnet

api laravel5 fractal transformer

18/08 2017

dev-analysis-XaNl5k

dev-analysis-XaNl5k

A simple fractal service provider and transformer generator with model attributes for laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar cyvelnet

api laravel5 fractal transformer

18/08 2017

v2.1.5

2.1.5.0

A simple fractal service provider and transformer generator with model attributes for laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar cyvelnet

api laravel5 fractal transformer

14/08 2017

v2.1.4

2.1.4.0

A simple fractal service provider and transformer generator with model attributes for laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar cyvelnet

api laravel5 fractal transformer

13/08 2017

v2.1.3

2.1.3.0

A simple fractal service provider and transformer generator with model attributes for laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar cyvelnet

laravel5 fractal api transformer

11/08 2017

v2.1.2

2.1.2.0

A simple fractal service provider and transformer generator with model attributes for laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar cyvelnet

laravel5 fractal api transformer

04/08 2017

v2.1.1

2.1.1.0

A simple fractal service provider and transformer generator with model attributes for laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar cyvelnet

laravel5 fractal api transformer

25/07 2017

v2.1.0

2.1.0.0

A simple fractal service provider and transformer generator with model attributes for laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar cyvelnet

laravel5 fractal api transformer

13/02 2017

2.0.2

2.0.2.0

A simple fractal service provider and transformer generator with model attributes for laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar cyvelnet

laravel5 fractal api transformer

01/02 2017

2.0.1

2.0.1.0

A simple fractal service provider and transformer generator with model attributes for laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar cyvelnet

laravel5 fractal api transformer

13/09 2016

v2.0

2.0.0.0

A simple fractal service provider and transformer generator with model attributes for laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar cyvelnet

laravel5 fractal api transformer

13/09 2016

dev-analysis-Xl7A9V

dev-analysis-Xl7A9V

A simple fractal service provider and transformer generator with model attributes for laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar cyvelnet

laravel5 fractal api transformer

13/09 2016

dev-analysis-ze6Ay4

dev-analysis-ze6Ay4

A simple fractal service provider and transformer generator with model attributes for laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar cyvelnet

laravel5 fractal api transformer

13/09 2016

dev-analysis-qJDdMo

dev-analysis-qJDdMo

A simple fractal service provider and transformer generator with model attributes for laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar cyvelnet

laravel5 fractal api transformer

11/08 2016

1.3.x-dev

1.3.9999999.9999999-dev

A simple fractal service provider and transformer generator for laravel 5.

  Sources   Download

MIT

The Requires

 

by Avatar cyvelnet

laravel5 fractal api transformer

11/08 2016

v1.3.2

1.3.2.0

A simple fractal service provider and transformer generator for laravel 5.

  Sources   Download

MIT

The Requires

 

by Avatar cyvelnet

laravel5 fractal api transformer

23/12 2015

v1.3.1

1.3.1.0

A simple fractal service provider and transformer generator for laravel 5.

  Sources   Download

MIT

The Requires

 

by Avatar cyvelnet

laravel5 fractal api transformer

22/12 2015

v1.3

1.3.0.0

A simple fractal service provider and transformer generator for laravel 5.

  Sources   Download

MIT

The Requires

 

by Avatar cyvelnet

laravel5 fractal api transformer

14/10 2015

v1.2.1

1.2.1.0

A simple fractal service provider and transformer generator for laravel 5.

  Sources   Download

MIT

The Requires

 

by Avatar cyvelnet

laravel5 fractal api transformer

19/07 2015

1.2

1.2.0.0

A simple fractal service provider and transformer generator for laravel 5.

  Sources   Download

MIT

The Requires

 

by Avatar cyvelnet

laravel5 fractal api transformer

01/07 2015

v1.1.4

1.1.4.0

A simple fractal service provider and transformer generator for laravel 5.

  Sources   Download

MIT

The Requires

 

by Avatar cyvelnet

laravel5 fractal api transformer

10/06 2015

v1.1.3

1.1.3.0

A simple fractal service provider and transformer generator for laravel 5.

  Sources   Download

MIT

The Requires

 

by Avatar cyvelnet

laravel5 fractal api transformer

29/03 2015

v1.1.2

1.1.2.0

A simple fractal service provider and transformer generator for laravel 5.

  Sources   Download

MIT

The Requires

 

by Avatar cyvelnet

laravel5 fractal api transformer

29/03 2015

v1.1.1

1.1.1.0

A simple fractal service provider and transformer generator for laravel 5.

  Sources   Download

MIT

The Requires

 

by Avatar cyvelnet

laravel5 fractal api transformer

19/03 2015

v1.1.0

1.1.0.0

A simple fractal service provider and transformer generator for laravel 5.

  Sources   Download

MIT

The Requires

 

by Avatar cyvelnet

laravel5 fractal api transformer

18/03 2015

1.0.x-dev

1.0.9999999.9999999-dev

A simple fractal service provider and transformer generator for laravel 5.

  Sources   Download

MIT

The Requires

 

by Avatar cyvelnet

laravel5 fractal api transformer

18/03 2015

v1.0.1

1.0.1.0

A simple fractal service provider and transformer generator for laravel 5.

  Sources   Download

MIT

The Requires

 

by Avatar cyvelnet

laravel5 fractal api transformer

18/03 2015

v1.0

1.0.0.0

A simple fractal service provider and transformer generator for laravel 5.

  Sources   Download

MIT

The Requires

 

by Avatar cyvelnet

laravel5 fractal api transformer