PHPackages                             gergonzalez/lumen-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. gergonzalez/lumen-fractal

ActiveLaravel-package[API Development](/categories/api)

gergonzalez/lumen-fractal
=========================

League Fractal Wrapper

165PHP

Since Apr 7Pushed 8y ago2 watchersCompare

[ Source](https://github.com/gergonzalez/lumen-fractal)[ Packagist](https://packagist.org/packages/gergonzalez/lumen-fractal)[ RSS](/packages/gergonzalez-lumen-fractal/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

Lumen Fractal wrapper package
=============================

[](#lumen-fractal-wrapper-package)

This package provides an easy way to use [Fractal](http://fractal.thephpleague.com/) in Lumen.

[Fractal](http://fractal.thephpleague.com/) provides a presentation and transformation layer for complex data output, the like found in RESTful APIs.

Getting Started
---------------

[](#getting-started)

### Prerequisites

[](#prerequisites)

- Lumen &lt;= 5.4
- Lumen &gt; 5.4 - Not tested yet

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

[](#installation)

Pull it via composer:

```
composer require gergonzalez/lumen-fractal
```

Once installed, register the service provider in your **bootstrap/app.php**

```
//Register Service Providers

$app->register(Gergonzalez\Fractal\FractalServiceProvider::class);
```

Usage
-----

[](#usage)

Implement your transformers, add a folder at **app/Http/Transformers** and put them there.

For example, **UserTransformer.php**:

```
namespace App\Http\Transformers;

use League\Fractal\TransformerAbstract;
use App\User;

class UserTransformer extends TransformerAbstract
{
    protected $availableIncludes = [
    ];

    protected $defaultIncludes = [
    ];

    /**
     * Turn User object into a generic array.
     *
     * @return array
     */
    public function transform(User $user)
    {
        return [
            'id' => $user->id,
            'email' => $user->email,
        ];
    }
}
```

And then, at your controller, if you retrieve only one item:

```
	use App\Http\Transformers\UserTransformer;

	class UserController extends Controller
	{

	    public function show(Request $request, $userId)
	    {
	        $user = User::findOrFail($userId);

	        return response()->json(app('fractal')->item($user, new UserTransformer())->getArray());
	    }

	}
```

Or a collection:

```
	use App\Http\Transformers\UserTransformer;

	class UserController extends Controller
	{

	    public function index(Request $request)
	    {
	        return response()->json(app('fractal')->collection(User::all(), new UserTransformer())->getArray());
	    }
	}
```

You can also use includes, defaults, etc. WIP docs.

If you need a real example of use, you can check [here](https://github.com/gergonzalez/funacademy-test)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/99d7aaa6a87c85c19eca1209a11d0745778ccbe6de6c49463fb78bcd404a22dc?d=identicon)[gergonzalez](/maintainers/gergonzalez)

---

Tags

composerlumen

### Embed Badge

![Health badge](/badges/gergonzalez-lumen-fractal/health.svg)

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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