PHPackages                             hasandotprayoga/format-response - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. hasandotprayoga/format-response

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hasandotprayoga/format-response
===============================

Laravel Format Response

v1.2.4(7y ago)12341

Since Feb 27Compare

[ Source](https://github.com/hasandotprayoga/format-response)[ Packagist](https://packagist.org/packages/hasandotprayoga/format-response)[ RSS](/packages/hasandotprayoga-format-response/feed)WikiDiscussions Synced 2d ago

READMEChangelog (2)DependenciesVersions (3)Used By (1)

Laravel Format Response For API
===============================

[](#laravel-format-response-for-api)

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

[](#installation)

Add to composer.json

```
    "require": {
        ...
        "hasandotprayoga/format-response": "*"
    }

```

On your terminal, run `composer update`

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

[](#configuration)

1. Open `app\Http\Controllers\Controller.php`, add one line like this:

    ```
    class Controller extends BaseController
    {
        use \FormatResponse\FormatResponse; // add this line
    }
    ```
2. Open `app\Exceptions\Handler.php`, edit method render like this:

    ```
    public function render($request, Exception $exception)
    {
        if($exception instanceof ValidationException) {
            return parent::render($request, $exception);
        }

        $rendered = parent::render($request, $exception);

        $error = [
            'error'=>$exception->getMessage(),
            'file'=>$exception->getFile(),
            'line'=>$exception->getLine()
        ];

        $controller = app('\App\Http\Controllers\Controller');
        $controller->responseCode = $rendered->getStatusCode();
        $controller->messages = $error;

        return $controller->response();
    }
    ```

How to use
----------

[](#how-to-use)

Change your return response to **$this-&gt;response();**

```
$this->response($results, $resCode, $messages, $metaData, $request);
/*
    @param $results default []
    @param $resCode default 200
    @param $messages default ''
    @param $metaData default []
    @param $request default []
*/

```

Example

```
return $this->response([1,2,4], 200, 'ok', [
    'selectedPage' => 1,
    'selectedItem' => NULL,
    'totalPage' => 2,
    'totalItem' => 5,
    'totalItemPerPage' => 5
], [
    'get'=>[
        'field1'=>1,
        'field2'=>2
    ],
    'post'=>[]
]);

// Or

$this->results = [1,2,4];
$this->resCode = 200;
$this->messages = 'Ok';
$this->metaData = [
    'selectedPage' => 1,
    'selectedItem' => NULL,
    'totalPage' => 2,
    'totalItem' => 5,
    'totalItemPerPage' => 5
];
$this->request = [
    'get'=>[
        'field1'=>1,
        'field2'=>2
    ],
    'post'=>[]
];

return $this->response();

```

Example Response
----------------

[](#example-response)

```
{
    "code": 200,
    "description": "Ok",
    "response": {
        "results": [
            {
                "id": 1,
                "balance": 100000,
                "recStatus": "DELETE",
                "recTimeCreate": "2019-01-16 17:10:01",
                "recTimeUpdate": "2019-01-29 04:39:22"
            },
            {
                "id": 2,
                "balance": null,
                "recStatus": "PUBLISH",
                "recTimeCreate": "2018-04-12 23:36:03",
                "recTimeUpdate": null
            },
            {
                "id": 3,
                "balance": null,
                "recStatus": "PUBLISH",
                "recTimeCreate": "2018-04-12 23:10:03",
                "recTimeUpdate": null
            },
        ],
        "messages": "ok",
        "metaData": {
            "selectedPage": 1,
            "selectedItem": null,
            "totalPage": 1,
            "totalItem": 3,
            "totalItemPerPage": 3
        }
    },
    "request": {
        "get": {
            "id": "1"
        }
    },
}
```

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

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

Total

2

Last Release

2679d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/18098141?v=4)[Hasan Prayoga](/maintainers/hasandotprayoga)[@hasandotprayoga](https://github.com/hasandotprayoga)

---

Top Contributors

[![hasandotprayoga](https://avatars.githubusercontent.com/u/18098141?v=4)](https://github.com/hasandotprayoga "hasandotprayoga (29 commits)")

### Embed Badge

![Health badge](/badges/hasandotprayoga-format-response/health.svg)

```
[![Health](https://phpackages.com/badges/hasandotprayoga-format-response/health.svg)](https://phpackages.com/packages/hasandotprayoga-format-response)
```

PHPackages © 2026

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