PHPackages                             thomzee/laramap - 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. thomzee/laramap

ActivePackage

thomzee/laramap
===============

Laravel REST API response mapper.

v1.4.0(5y ago)4472MITPHPPHP &gt;=5.4

Since Oct 11Pushed 5y agoCompare

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

READMEChangelogDependencies (4)Versions (6)Used By (0)

[![SymfonyInsight](https://camo.githubusercontent.com/85e061d62f4d334b02e9c9559390dd4103555949e884eb6ed1ac83b643590053/68747470733a2f2f696e73696768742e73796d666f6e792e636f6d2f70726f6a656374732f34656538316165642d363830372d343431662d386334322d3962373130353365333162642f6d696e692e737667)](https://insight.symfony.com/projects/4ee81aed-6807-441f-8c42-9b71053e31bd)[![Latest Stable Version](https://camo.githubusercontent.com/735bf6364eddc558b61d458f7886ffaf9f4b6b30e7cc841544018c74188d8db4/68747470733a2f2f706f7365722e707567782e6f72672f74686f6d7a65652f6c6172616d61702f76657273696f6e)](https://packagist.org/packages/thomzee/laramap)[![Total Downloads](https://camo.githubusercontent.com/f0044582ab162eca14c1c6aab3d5fb52baaa14418d0b463fa2f1198836f56308/68747470733a2f2f706f7365722e707567782e6f72672f74686f6d7a65652f6c6172616d61702f646f776e6c6f616473)](https://packagist.org/packages/thomzee/laramap)[![Latest Unstable Version](https://camo.githubusercontent.com/de1aa45ca5399ce49d68627fb8fbe7c83ab709601d549b3b0e0efdb56effe8b2/68747470733a2f2f706f7365722e707567782e6f72672f74686f6d7a65652f6c6172616d61702f762f756e737461626c65)](//packagist.org/packages/thomzee/laramap)[![License](https://camo.githubusercontent.com/26741bf5dc29f21e0954ff58f7f970c99800f0fabcb6f55ae0bc0c15ec8fa6a0/68747470733a2f2f706f7365722e707567782e6f72672f74686f6d7a65652f6c6172616d61702f6c6963656e7365)](https://packagist.org/packages/thomzee/laramap)

Laramap
=======

[](#laramap)

Introduction
------------

[](#introduction)

Every laravel API projects need a map to avoid get lost in the response jungle. Laramap is a Laravel package for object or array mapping in order to give a mature REST API response easier and cleaner.

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

[](#installation)

You can choose one of those two installation methods freely.

#### 1. Automatic Installation

[](#1-automatic-installation)

Go into your project root folder laravel

```
cd YOUR_LARAVEL_ROOT_PROJECT/

```

then get the latest version of Laramap on your project with following command.

```
composer require thomzee/laramap

```

#### 2. Manual Installation

[](#2-manual-installation)

Alternatively, you can update your composer.json file, just like code below

```
"require": {
    . . .
    "thomzee/laramap": "dev-master"
},

```

b. then run `composer install` command.

Register Service
----------------

[](#register-service)

Firstly you need register the service provider your project configuration file `config/app.php`

```
'providers' => [
    . . .
    Thomzee\Laramap\LaramapServiceProvider::class,
]

```

and the facade as well in same file.

```
'aliases' => [
    . . .
    'Laramap' => Thomzee\Laramap\Facades\Laramap::class,
]

```

Run `composer dump-autoload` command to update changes in your project configuration file.

```
composer dump-autoload

```

Mapper Class Generator
----------------------

[](#mapper-class-generator)

Make sure `php artisan make:mapper` is exist, and list artisan command with

```
php artisan list

```

then generate a mapper file with artisan command, example:

```
php artisan make:mapper UserMapper

```

Update the content of single() method. The array keys is attributes of the response and $item is a representation of single object or array, example:

```
function single($item)
{
    return [
        "name" => $item->name,
        "email" => $item->email,
        "join_date" => $item->created_at,
    ];
}

```

Features
--------

[](#features)

Import the package in above of your controller class.

```
use Laramap;

```

That's it. That is because you has registered the package in your project configuration file.

#### 1. Paginated Data

[](#1-paginated-data)

Get list of paginated data with pages information. First parameter must be Mapper class you generated before and the second must be instance of `Illuminate\Contracts\Pagination\Paginator`. You can do where clause and other query builder functions before finally you call the paginate() function here.

```
public function index()
{
    return Laramap::paged(\App\Mappers\UserMapper::class, \App\User::paginate(10));
}

```

the code above, using Mapper the one we create earlier which is `UserMapper` class, and the result is like this

```
{
    "meta": {
        "code": 200,
        "status": "success",
        "message": "Operation successfully executed."
    },
    "pages": {
        "per_page": 10,
        "current_page": 1,
        "last_page": 1,
        "has_more_pages": false,
        "from": 1,
        "to": 3
    },
    "links": {
        "self": 10,
        "next": null,
        "prev": null
    },
    "data": [
        {
            "name": Alex
        },
        {
            "name": Thomas
        },
        {
            "name": Uje
        }
    ]
}

```

#### 2. Single Data

[](#2-single-data)

Get single object or array. You can even fill it with a Laravel collection

```
public function show($id)
{
    return Laramap::single(\App\Mappers\UserMapper::class, \App\User::find($id));
}

```

and the result is like this

```
{
    "meta": {
        "code": 200,
        "status": "success",
        "message": "Operation successfully executed."
    },
    "data": {
        "name": Thomas
    }
}

```

#### 3. List Data

[](#3-list-data)

Get list data (array data) without paginate the items, with this example code

```
public function all()
{
    return Laramap::list(\App\Mappers\UserMapper::class, \App\User::paginate(10));
}

```

and the result is something like this.

```
{
    "meta": {
        "code": 200,
        "status": "success",
        "message": "Operation successfully executed."
    },
    "data": [
        {
            "name": Alex
        },
        {
            "name": Thomas
        },
        {
            "name": Uje
        }
    ]
}

```

#### 4. Success Response

[](#4-success-response)

Response success meta, with no parameters.

```
public function all()
{
    return Laramap::success();
}

```

#### 4. Error Response

[](#4-error-response)

or and error meta.

```
public function all()
{
    return Laramap::error();
}

```

#### 5. Response For Validation

[](#5-response-for-validation)

Response Laravel Validation errors bag

```
$validator = Validator::make($request->all(), [
    'foo' => 'required',
    'bar' => 'required'
]);
if ($validator->fails()) {
    return Laramap::validation($validator);
}

```

the result is

```
{
    "meta": {
        "code": 422,
        "status": "validation_error",
        "message": "Oops, something went wrong.",
        "errors": {
            "foo": [
                "The foo field is required."
            ],
            "bar": [
                "The bar field is required."
            ]
        }
    }
}

```

License
-------

[](#license)

This package is open-sourced software licensed under the MIT license.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 79.5% 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 ~178 days

Total

3

Last Release

2045d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/92025e5db63780633ccc78d34c9489b9f8ac113acbcfd8403e5d917ca149b15f?d=identicon)[thomzee](/maintainers/thomzee)

---

Top Contributors

[![thomzee](https://avatars.githubusercontent.com/u/7501454?v=4)](https://github.com/thomzee "thomzee (35 commits)")[![huzairuje](https://avatars.githubusercontent.com/u/4037159?v=4)](https://github.com/huzairuje "huzairuje (9 commits)")

### Embed Badge

![Health badge](/badges/thomzee-laramap/health.svg)

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

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M529](/packages/laravel-passport)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M106](/packages/laravel-cashier)[yadahan/laravel-authentication-log

Laravel Authentication Log provides authentication logger and notification for Laravel.

416632.8k5](/packages/yadahan-laravel-authentication-log)[laravel/cashier-paddle

Cashier Paddle provides an expressive, fluent interface to Paddle's subscription billing services.

264778.4k3](/packages/laravel-cashier-paddle)[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)

PHPackages © 2026

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