PHPackages                             tychovbh/laravel-resource-mapper - 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. tychovbh/laravel-resource-mapper

ActiveLibrary

tychovbh/laravel-resource-mapper
================================

Map data from external Resources in Laravel

v0.2(7y ago)059MITPHPPHP ^7.1.3

Since Nov 2Pushed 7y ago1 watchersCompare

[ Source](https://github.com/tychovbh/laravel-resource-mapper)[ Packagist](https://packagist.org/packages/tychovbh/laravel-resource-mapper)[ Docs](https://github.com/tychovbh/laravel-resource-mapper)[ RSS](/packages/tychovbh-laravel-resource-mapper/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (5)Versions (3)Used By (0)

laravel-resource-mapper
=======================

[](#laravel-resource-mapper)

[![Latest Version on Packagist](https://camo.githubusercontent.com/61b18380e63617dca7208f48951720ebba0d80bac34963ba52f8274a6fb3e466/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f747963686f7662682f6c61726176656c2d7265736f757263652d6d61707065722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tychovbh/laravel-resource-mapper)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/c0e321c7b9243de8f61d2056db201ef48cff8381779f5194f5d388eeedb499f5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f747963686f7662682f6c61726176656c2d7265736f757263652d6d61707065722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tychovbh/laravel-resource-mapper)

Laravel Resource Mapper is created by, and is maintained by Tycho, and is a Laravel/Lumen package to map data from external Resources. Feel free to check out the [change log](CHANGELOG.md), [releases](https://github.com/tychovbh/laravel-bluebillywig/releases), [license](LICENSE.md), and [contribution guidelines](CONTRIBUTING.md)

Install
-------

[](#install)

Laravel Resource Mapper requires PHP 7.1 or 7.2. This particular version supports Laravel 5.5 - 5.7 only and Lumen.

To get the latest version, simply require the project using Composer.

```
$ composer require tychovbh/laravel-resource-mapper
```

Once installed, if you are not using automatic package discovery, then you need to register the `Tychovbh\ResourceMapper\ResourceMapperServiceProvider` service provider in your `config/app.php`.

In Lumen add de Service Provider in `bootstrap/app.php`:

```
$app->register(\Tychovbh\ResourceMapper\ResourceMapperServiceProvider::class);
```

Configuration
-------------

[](#configuration)

Laravel Resource Mapper has mapping configuration.

To get started, you'll can publish all vendor assets:

```
$ php artisan vendor:publish --tag=laravel-resource-mapper
```

This will create a `config/resource-mapper.php` file in your app that you can modify to set your configuration. Also, make sure you check for changes to the original config file in this package between releases.

In lumen you have to create the configuration file manually since `vendor:publish` is not available. Create the file `config/resource-mapper.php` and copy paste the [example file](https://github.com/tychovbh/laravel-resource-mapper/blob/master/config/resource-mapper.php).

You can add as many mappings as you wish give them a name that looks like your API endpoint:

```
use Tychovbh\ResourceMapper\RawResource;

// Let's say i'm retrieving a User, Company and Person from an api:
return [
    'user' => [
        // this will map ['RawEmail' => 'some@email.com'] to ['email' => 'some@email.com']
        'email' => 'RawEmail'
    ]
    'company' => [
        // You can map recursive resource value as well via dot notation
        // this will map: ['company' => ['name' => 'Bespoke Web']] to ['company' => 'Bespoke Web']
        'company' => 'company.name'
    ]
    'person' => [
        // You can also set a callback, then a RawResource object will be available.
        // You can use RawResource to access all resource values and map is as you like.
        // this will map ['RawFirstname' => 'john'] to ['firstname' => 'John']
        'firstname' => function (RawResource $resource) {
            return ucfirst($resource->get('RawFirstname'));
        }
        // this will map ['firstname' => 'John', 'suffix' => 'v.', 'lastname' => 'Doe'] to ['fullname' => 'John v. Doe']
        'fullname' => function (RawResource $resource) {
            return $resource->join(' ', 'firstname', 'suffix', 'lastname');
        }
    ]
    // You can also do some recursive array mapping
    'company' => [
        'user' => function (RawResource $resource) {
            return $this->config('user')->map($resource->get('RawCompany.RawUser'));
        }
    ],
    'users' => [
        'items' => function (RawResource $resource) {
            return $this->config('user')->mapCollection($resource->get('RawItems'));
        }
    ]
];
```

Usage
-----

[](#usage)

##### Real Examples

[](#real-examples)

Instantiate ResourceMapper class:

```
use Tychovbh\ResourceMapper\ResourceMapper;

// Use class injection
Route::get('/user', function(ResourceMapper $mapper) {
    $res = $guzzleClient->request('GET', 'https://some-api.com/user');
    $result = json_decode($res->getBody()->getContents(), true);
    return $mapper->config('user')->map($result);
});

// Or use Laravel helper app()
Route::get('/user', function() {
    $mapper = app('resource-mapper');
    $res = $guzzleClient->request('GET', 'https://some-api.com/user');
    $result = json_decode($res->getBody()->getContents(), true);
    return $mapper->config('user')->map($result);
});
```

Available ResourceMapper methods:

```
// Map via config with $RawResource as array
$mapped = $mapper->config('user')->map($RawResource)

// Map via config with $RawResource as json
$mapped = $mapper->config('user')->mapJson($RawResource)

// Skip config file and use custom mapping
$mapped = $mapper->mapping([
    'title' => 'RawTitle'
])->map($RawResource)

// Map via config with a $RawResource as a Collection of items
$mapped = $mapper->config('user')->mapCollection([
    [
        'RawFistname' => 'John',
    ],
    [
        'RawFistname' => 'Alex',
    ],
])
```

Available RawResource methods:

```
$RawResource = new RawResource([
    'title' => 'my new website',
    'firstname' => 'John',
    'prefix' => 'v',
    'lastname' => 'Doe',
    'company' => [
        'name' => 'Bespoke Web'
    ]
])

// Get value from array
$title = $RawResource->get('title')
echo $title; // my new website

// Get recursive value from array
$company = $RawResource->get('company.name')
echo $company; // Bespoke Web

// Join values from array with a delimiter
$title = $RawResource->join(' ', 'firstname', 'prefix, 'lastname')
echo $title; // John v Doe
```

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Tycho](https://github.com/tychovbh)

License
-------

[](#license)

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

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 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 ~191 days

Total

2

Last Release

2556d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6600cf089af73eb1be53eb4c47bccd04794564d6e9c8d9386cd19ab2b42fd06e?d=identicon)[bespokeweb](/maintainers/bespokeweb)

---

Top Contributors

[![tychovbh](https://avatars.githubusercontent.com/u/5880561?v=4)](https://github.com/tychovbh "tychovbh (2 commits)")

---

Tags

tychovbhlaravel-resource-mapper

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/tychovbh-laravel-resource-mapper/health.svg)

```
[![Health](https://phpackages.com/badges/tychovbh-laravel-resource-mapper/health.svg)](https://phpackages.com/packages/tychovbh-laravel-resource-mapper)
```

###  Alternatives

[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-prometheus

Export Laravel metrics to Prometheus

2651.3M6](/packages/spatie-laravel-prometheus)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

44643.1k1](/packages/pressbooks-pressbooks)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[dragon-code/migrate-db

Easy data transfer from one database to another

15717.4k](/packages/dragon-code-migrate-db)

PHPackages © 2026

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