New

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

cyvelnet/laravel5-fractal

A simple fractal service provider and transformer generator with model attributes for laravel >=5.
190,797 79

Larablocks Analysis

cyvelnet/laravel5-fractal works with Laravel 5 to 11 (latest release v2.4.5, Mar 13, 2024), all past end of life (the last on Mar 12, 2026): no more fixes, even for security.

Recommendation checks

Not advised

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

  • No release or commit in over 2 years
  • Supports only Laravel 5 to 11, past end of life since Mar 12, 2026
  • No release in the last 12 months (last: Mar 13, 2024)
  • 505 downloads a month (needs 10,000)
  • 79 GitHub stars (needs 100)

State

Likely abandoned
  • No release or commit in over 2 years.
  • Last stable release: Mar 13, 2024.
  • No releases in the last 12 months.
  • First released: Mar 18, 2015.
  • Monthly downloads: 505, down 17% from six months ago.
  • 2 open issues on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Dec 1, 2026.

Install
composer require cyvelnet/laravel5-fractal
Latest Version:v2.4.5
PHP:^5.6|^7.0|^8.0
Laravel:5 – 11
License:MIT
Last Updated:Mar 13, 2024
Links: GitHub  ·  Packagist
Maintainer: cyvelnet

StyleCI Build Status Total Downloads Latest Stable Version Latest Unstable Version License

laravel5-fractal

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

Installation

Laravel

Require this package with composer using the following command:

composer require cyvelnet/laravel5-fractal

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

Cyvelnet\Laravel5Fractal\Laravel5FractalServiceProvider::class,

and register Facade And optionally add a new line to the aliases array:

'Fractal' => Cyvelnet\Laravel5Fractal\Facades\Fractal::class

Lumen

register service provider in /bootstrap/app.php for lumen

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

and uncomment the line

$app->withFacades();

and finally register Facade with

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

Config

You can also publish the config file to change implementations to suits you.

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

autoload => true

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

 // 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


$user = User::find(1);

Fractal::item($user, new UserTransformer());

Fractal::collection();

Transform a collection of records


$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


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

Fractal::excludes()

Remove sub resources


Fractal::excludes('orders')

Fractal::setSerializer()

Change transformer serializer


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

Fractal::fieldsets()

add sparse fieldset


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

Fractal::addMeta()

add extra meta data to root


// 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

Sub Relationship Modifier

https://github.com/Cyvelnet/laravel5-fractal/wiki/Sub-Relationship-Modifier

Extra

https://github.com/Cyvelnet/laravel5-fractal/wiki/Custom-TransformerableAbstract-class

Alternatives to cyvelnet/laravel5-fractal

flugger/laravel-responder

A Laravel Fractal package for building API responses, giving you the power of Fr...

1,689,056 886
viodev/laravel-replier

Laravel package for making JSON APIs.

17,066 1

Version History

Version Released PHP Laravel License
v2.4.5 ^5.6|^7.0|^8.0 ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0 ||^10.0 || ^11.0 MIT
v2.4.4 ^5.6|^7.0|^8.0 ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0 MIT
v2.4.3 ^5.6|^7.0 ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0 MIT
v2.4.2 ^5.6|^7.0 ^5.0 || ^6.0 || ^7.0 || ^8.0 MIT
v2.4.1 ^5.6|^7.0 ^5.0 || ^6.0 || ^7.0 MIT