PHPackages                             nimbly/remodel - 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. nimbly/remodel

AbandonedArchivedLibrary[API Development](/categories/api)

nimbly/remodel
==============

A simple data transformer for your API responses

2.1(5y ago)312.4kMITPHPPHP &gt;=7.3|^8.0

Since Feb 1Pushed 5y ago1 watchersCompare

[ Source](https://github.com/nimbly/Remodel)[ Packagist](https://packagist.org/packages/nimbly/remodel)[ RSS](/packages/nimbly-remodel/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (4)Versions (7)Used By (0)

Remodel
=======

[](#remodel)

A simple data transformer for your API responses.

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

[](#installation)

```
composer require nimbly/remodel
```

Basic usage
-----------

[](#basic-usage)

Create a transformer that extends the `Nimbly\Remodel\Transformer` abstract. The `transform` method is required and should accept a single *thing* to transform. This *thing* could be a model object or a simple associative array or something else entirely - it really doesn"t matter.

Inside this method you will define and return the transformed data as an associative array.

```
use Nimbly\Remodel\Transformer;

class UserTransform extends Transformer
{
    public function transform(User $user): array
    {
        return [
            "id" => (int) $user->id,
            "name" => $user->name,
            "email" => $user->email,
            "created_at" => \date("c", $user->created_at)
        ];
    }
}
```

With our `UserTransformer` now defined, let's pull a user from the database and transform it. In order to transform the user data, we must map the data to be transformed to a specific transformer.

To do this we create a new `Item` subject since we are transforming a single item. If this were a collection of users, we would use the `Collection` subject.

```
// Grab the user from the database
$user = App\Models\User::find($id);

// Create a new Item subject using the UserTransformer
$subject = new Nimbly\Remodel\Subjects\Item($user, new UserTransformer);
```

Including related data automatically
------------------------------------

[](#including-related-data-automatically)

What good is a transformer if it can only transform the object you've given it? Real use cases are far more complex. What if you need to transform a book whose author is stored in a separate model instance and needs its own transformation? What if we need the most recent user reviews posted about the book?

Add the protected `$defaultIncludes` array property on the transformer containing all the default includes you would like. Remodel will then look for a method on the transformer with name "{include}Include". For example:

```
class BookTransformer extends Transformer
{
    protected $defaultIncludes = ["author", "reviews"];

    public function transform(Book $book): array
    {
        return [
            "id" => (int) $book->id,
            "title" => $book->title,
            "genre" => $book->genre,
            "isbn" => $book->isbn,
            "published_at" => date("c", $book->published_at)
        ];
    }

    /**
     *
     * Remodel will call this method automatically for you since it's in the list of
     * $defaultIncludes above.
     *
     */
    public function authorInclude(Book $book): Subject
    {
        return new Item($book->author, new AuthorTransformer);
    }

    /**
     *
     * Return an array of reviews.
     *
     */
    public function reviewsInclude(Book $book): Subject
    {
        return new Collection($book->reviews, new ReviewTransformer);
    }
}
```

Now let's create the Transformer for our Author object.

```
class AuthorTransformer extends Transformer
{
    public function transform(Author $author)
    {
        return [
            "id" => (int) $author->id,
            "name" => $author->name
        ];
    }
}
```

Nested includes
---------------

[](#nested-includes)

What if you need an optional include on another include? For example, if the Author also has an Address object that is not included by default?

You can nest includes by using a dot notation.

```
protected $defaultIncludes = ["author.address"];
```

This will include an Author and its Address object.

You can nest as many includes as you"d like and to an unlimited depth.

```
protected $defaultIncludes = ["comments.user.profile"];
```

Transforming a collection of subjects
-------------------------------------

[](#transforming-a-collection-of-subjects)

You can transform a collection or array of subjects in a similar fashion.

```
$collection = new Nimbly\Remodel\Subjects\Collection($books, new BookTransformer);
```

Adding includes at run time
---------------------------

[](#adding-includes-at-run-time)

What if you don"t always need a related subject included with every transformation? Maybe it's a resource provided only when the requesting client needs it?

You can pass run-time user supplied includes into the Transformer instance using the `setIncludes` method.

```
$transformer = new BookTransformer;
$transformer->setIncludes(["author", "publisher"]);
```

Overriding default includes at run time
---------------------------------------

[](#overriding-default-includes-at-run-time)

You can override the default includes at runtime by calling the `setDefaultIncludes` method.

```
$transformer = new BookTransformer;
$transformer->setDefaultIncludes(["comments"]);
```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~215 days

Recently: every ~264 days

Total

6

Last Release

1950d ago

Major Versions

1.2 → 2.02020-12-31

PHP version history (2 changes)1.0PHP ~5.4 || ~7.0

2.0PHP &gt;=7.3|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/723164?v=4)[Brent Scheffler](/maintainers/brentscheffler)[@brentscheffler](https://github.com/brentscheffler)

---

Top Contributors

[![brentscheffler](https://avatars.githubusercontent.com/u/723164?v=4)](https://github.com/brentscheffler "brentscheffler (9 commits)")

---

Tags

responseapitransformer

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/nimbly-remodel/health.svg)

```
[![Health](https://phpackages.com/badges/nimbly-remodel/health.svg)](https://phpackages.com/packages/nimbly-remodel)
```

###  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)[nilportugues/laravel5-json-api

Laravel 5 JSON API Transformer Package

31232.4k1](/packages/nilportugues-laravel5-json-api)[nilportugues/jsonapi-bundle

Symfony 2 &amp; 3 JSON API Transformer Package

11446.0k](/packages/nilportugues-jsonapi-bundle)[nilportugues/json-api

Serializer transformers outputting valid API responses in JSON, JSON API and HAL+JSON API formats.

70106.2k3](/packages/nilportugues-json-api)[nilportugues/api-problems

PSR7 Response implementation for the Problem Details for HTTP APIs

1749.4k2](/packages/nilportugues-api-problems)[nilportugues/hal

HAL+JSON &amp; HAL+XML API transformer outputting valid API responses.

317.7k2](/packages/nilportugues-hal)

PHPackages © 2026

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