PHPackages                             cyvelnet/laravel5-fractal - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. cyvelnet/laravel5-fractal

ActiveLibrary[API Development](/categories/api)

cyvelnet/laravel5-fractal
=========================

A simple fractal service provider and transformer generator with model attributes for laravel &gt;=5.

v2.4.5(2y ago)79187.2k—7.1%21[1 issues](https://github.com/Cyvelnet/laravel5-fractal/issues)[1 PRs](https://github.com/Cyvelnet/laravel5-fractal/pulls)1MITPHPPHP ^5.6|^7.0|^8.0CI failing

Since Mar 18Pushed 2y ago5 watchersCompare

[ Source](https://github.com/Cyvelnet/laravel5-fractal)[ Packagist](https://packagist.org/packages/cyvelnet/laravel5-fractal)[ RSS](/packages/cyvelnet-laravel5-fractal/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (36)Used By (1)

[![StyleCI](https://camo.githubusercontent.com/2c48ce189908bb3a0dbd98db528913691e37d10981f4b62b20e291f0649f3e03/68747470733a2f2f7374796c6563692e696f2f7265706f732f33323430363930342f736869656c64)](https://styleci.io/repos/32406904)[![Build Status](https://camo.githubusercontent.com/c1013dcf0a1606bbd6c357f9cd8d7349ca685c75063fe57d34a4c6377e4da065/68747470733a2f2f7472617669732d63692e6f72672f437976656c6e65742f6c61726176656c352d6672616374616c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Cyvelnet/laravel5-fractal)[![Total Downloads](https://camo.githubusercontent.com/e75d9b0bf89ae2bef6a8d938cb4ca0764cbda95dc1f47e300b06a855691969dd/68747470733a2f2f706f7365722e707567782e6f72672f637976656c6e65742f6c61726176656c352d6672616374616c2f646f776e6c6f616473)](https://packagist.org/packages/cyvelnet/laravel5-fractal)[![Latest Stable Version](https://camo.githubusercontent.com/49ae767a0a7da26586e7c09634f4d29beeb7be93cb58af67fd73233773de603d/68747470733a2f2f706f7365722e707567782e6f72672f637976656c6e65742f6c61726176656c352d6672616374616c2f762f737461626c65)](https://packagist.org/packages/cyvelnet/laravel5-fractal)[![Latest Unstable Version](https://camo.githubusercontent.com/c7f05ab65eeac42eedbaa38e0fa7e1266ddea7dd16d292e96feaa829c9c0010b/68747470733a2f2f706f7365722e707567782e6f72672f637976656c6e65742f6c61726176656c352d6672616374616c2f762f756e737461626c65)](https://packagist.org/packages/cyvelnet/laravel5-fractal)[![License](https://camo.githubusercontent.com/ec535a7600e6fd02ae7367f0f428bb6902006ffd72157730448de3d94377d628/68747470733a2f2f706f7365722e707567782e6f72672f637976656c6e65742f6c61726176656c352d6672616374616c2f6c6963656e7365)](https://packagist.org/packages/cyvelnet/laravel5-fractal)

laravel5-fractal
================

[](#laravel5-fractal)

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

- [Installation](#installation)
- [Config](#config)
- [Command](#command)
- [Usage](#usage)
- [Trait](#trait) (Optional feature &gt;= 2.1.3)
- [Sub Relationship Modifier](#trait) (Optional feature &gt;=2.4.0)
- [Extra](#extra) Extra

Installation
------------

[](#installation)

#### Laravel

[](#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' =&gt; Cyvelnet\\Laravel5Fractal\\Facades\\Fractal::class

#### Lumen

[](#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

[](#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.

[](#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

[](#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

[](#usage)

### Fractal::item();

[](#fractalitem)

Transform a single record

```
$user = User::find(1);

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

### Fractal::collection();

[](#fractalcollection)

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()

[](#fractalincludes)

Inject sub resources

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

### Fractal::excludes()

[](#fractalexcludes)

Remove sub resources

```
Fractal::excludes('orders')
```

### Fractal::setSerializer()

[](#fractalsetserializer)

Change transformer serializer

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

### Fractal::fieldsets()

[](#fractalfieldsets)

add sparse fieldset

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

### Fractal::addMeta()

[](#fractaladdmeta)

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

[](#trait)

Sub Relationship Modifier
-------------------------

[](#sub-relationship-modifier)

Extra
-----

[](#extra)

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity47

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 94.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~102 days

Recently: every ~367 days

Total

33

Last Release

797d ago

Major Versions

1.3.x-dev → v2.02016-09-13

PHP version history (4 changes)v1.0PHP &gt;=5.4.0

v2.0PHP &gt;=5.5.9

v2.1.4PHP ^5.6|^7.0

v2.4.4PHP ^5.6|^7.0|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/e1a4747ac3123b2f527a84df431e930c7f232773d741aff681aedf953e3a80f1?d=identicon)[cyvelnet](/maintainers/cyvelnet)

---

Top Contributors

[![Cyvelnet](https://avatars.githubusercontent.com/u/11516087?v=4)](https://github.com/Cyvelnet "Cyvelnet (130 commits)")[![SeoFood](https://avatars.githubusercontent.com/u/2766011?v=4)](https://github.com/SeoFood "SeoFood (2 commits)")[![2bj](https://avatars.githubusercontent.com/u/71068?v=4)](https://github.com/2bj "2bj (1 commits)")[![hootlex](https://avatars.githubusercontent.com/u/6147968?v=4)](https://github.com/hootlex "hootlex (1 commits)")[![joedawson](https://avatars.githubusercontent.com/u/1009696?v=4)](https://github.com/joedawson "joedawson (1 commits)")[![hackel](https://avatars.githubusercontent.com/u/583677?v=4)](https://github.com/hackel "hackel (1 commits)")[![clarkeash](https://avatars.githubusercontent.com/u/1612186?v=4)](https://github.com/clarkeash "clarkeash (1 commits)")

---

Tags

apilaraveltransformerfractal

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cyvelnet-laravel5-fractal/health.svg)

```
[![Health](https://phpackages.com/badges/cyvelnet-laravel5-fractal/health.svg)](https://phpackages.com/packages/cyvelnet-laravel5-fractal)
```

###  Alternatives

[flugger/laravel-responder

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

8901.5M5](/packages/flugger-laravel-responder)[spatie/laravel-fractal

An easy to use Fractal integration for Laravel applications

1.9k15.1M99](/packages/spatie-laravel-fractal)[yajra/laravel-datatables-fractal

Laravel DataTables Fractal Plugin.

966.9M29](/packages/yajra-laravel-datatables-fractal)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
