2017 © Pedro Peláez
 

library laravel-fractal

A Laravel Service Provider for Fractal

image

gathercontent/laravel-fractal

A Laravel Service Provider for Fractal

  • Tuesday, November 29, 2016
  • by acairns
  • Repository
  • 8 Watchers
  • 52 Stars
  • 31,600 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 12 Forks
  • 6 Open issues
  • 8 Versions
  • 9 % Grown

The README.md

Laravel Fractal

A Laravel Service Provider for League/Fractal., (*1)


Installation

Add laravel-fractal to your composer.json file:, (*2)

"require": {
    "gathercontent/laravel-fractal": "~1.0"
}

Get composer to install the package:, (*3)

$ composer require gathercontent/laravel-fractal

Registering the Package

Register the service provider within the providers array found in app/config/app.php:, (*4)

'providers' => array(
    // ...
    GatherContent\LaravelFractal\LaravelFractalServiceProvider::class
)

Add an alias within the aliases array found in app/config/app.php:, (*5)

'aliases' => array(
    // ...
    'Fractal' => GatherContent\LaravelFractal\LaravelFractalFacade::class,
)

Configuration

To override the default configuration, you can publish the config files to your application. Artisan can do this automatically for you via the command line:, (*6)

$ php artisan vendor:publish

Usage

Basic Example

Formatting a single item:, (*7)

// routes.php
Route::get('/me', array('before' => 'auth', function () {
    return Fractal::item(Auth::user(), new UserTransformer);
}));

Formatting a collection:, (*8)

// routes.php
Route::get('/comments', function () {
    return Fractal::collection(Comment::all(), new CommentTransformer);
});

Adding meta data:, (*9)

// routes.php
Route::get('/comments', function () {
    return Fractal::collection(Comment::all(), new CommentTransformer, function ($resources) {
        $resources->setMetaValue('foo', 'bar');
    });
});

Returning a paginated collection:, (*10)

// routes.php
Route::get('/comments', function () {
    return Fractal::collection(Comment::paginate(), new CommentTransformer);
});

Using a custom pagination adapter:, (*11)

// routes.php
Route::get('/comments', function () {
    $comments = Comment::paginate();
    $adapter = new MyIlluminatePaginationAdapter($comments);
    return Fractal::collection($comments, new CommentTransformer, null, $adapter);
});

The Versions

29/11 2016

dev-master

9999999-dev

A Laravel Service Provider for Fractal

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel fractal

29/11 2016

1.0.1

1.0.1.0

A Laravel Service Provider for Fractal

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel fractal

18/11 2016

dev-feature-update-for-laravel-5

dev-feature-update-for-laravel-5

A Laravel Service Provider for Fractal

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel fractal

18/11 2016

1.0.0

1.0.0.0

A Laravel Service Provider for Fractal

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel fractal

17/11 2014

0.1.2

0.1.2.0

A Laravel Service Provider for Fractal

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel fractal

17/11 2014

dev-develop

dev-develop

A Laravel Service Provider for Fractal

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel fractal

04/09 2014

0.1.1

0.1.1.0

A Laravel Service Provider for Fractal

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel fractal

26/08 2014

0.1.0

0.1.0.0

A Laravel Service Provider for Fractal

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel fractal