New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

gathercontent/laravel-fractal

A Laravel Service Provider for Fractal
163,249 50

Larablocks Analysis

gathercontent/laravel-fractal works with any PHP project: the latest release (1.0.1, Nov 29, 2016) doesn't depend on Laravel.

Recommendation checks

Not advised

Not advised: no release or commit in over 2 years.

  • No release or commit in over 2 years
  • No release in the last 12 months (last: Nov 29, 2016)
  • 458 downloads a month (needs 10,000)
  • 50 GitHub stars (needs 100)

State

Likely abandoned
  • No release or commit in over 2 years.
  • Last stable release: Nov 29, 2016.
  • No releases in the last 12 months.
  • First released: Aug 26, 2014.
  • Monthly downloads: 458, about the same as six months ago.
  • 6 open issues on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Nov 28, 2026.

Install
composer require gathercontent/laravel-fractal
Latest Version:1.0.1
PHP:>=5.3.0
License:MIT
Last Updated:Nov 29, 2016
Links: GitHub  ·  Packagist
Maintainer: gathercontent

Laravel Fractal

A Laravel Service Provider for League/Fractal.


Installation

Add laravel-fractal to your composer.json file:

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

Get composer to install the package:

$ composer require gathercontent/laravel-fractal

Registering the Package

Register the service provider within the providers array found in app/config/app.php:

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

Add an alias within the aliases array found in app/config/app.php:

'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:

$ php artisan vendor:publish

Usage

Basic Example

Formatting a single item:

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

Formatting a collection:

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

Adding meta data:

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

Returning a paginated collection:

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

Using a custom pagination adapter:

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

Related Packages

m4tthumphrey/fractal-laravel

Laravel bindings for the Fractal library.

2,568 4
ellipsesynergie/api-response

Simple package to handle response properly in your API

1,444,398 370
appkr/api

RESTful HTTP API dev tool for Laravel or Lumen based project

15,164 31
codingphase/fractalfy

Laravel wrapper for Fractal.

4,391 1
hesto/fractalfy

Laravel wrapper for Fractal.

1,609 0

Version History

Version Released PHP License
1.0.1 >=5.3.0 MIT
1.0.0 >=5.3.0 MIT
0.1.2 >=5.3.0 MIT
0.1.1 >=5.3.0 MIT
0.1.0 >=5.3.0 MIT