PHPackages                             arinasystems/laravel-json-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. arinasystems/laravel-json-response

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

arinasystems/laravel-json-response
==================================

Easily generate a JSON response in laravel.

1.0.4(4y ago)25.7kMITPHPPHP ^7.2.5|^8.0CI failing

Since Jun 24Pushed 4y ago1 watchersCompare

[ Source](https://github.com/arinasystems/laravel-json-response)[ Packagist](https://packagist.org/packages/arinasystems/laravel-json-response)[ Docs](https://github.com/arinasystems/laravel-json-response)[ RSS](/packages/arinasystems-laravel-json-response/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (9)Dependencies (3)Versions (14)Used By (0)

[![Laravel JSON Response Cover](./docs/laravel-json-response.gif)](./docs/laravel-json-response.gif)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e6476bb1c23a4524852c24500762ac8ddd4f6f1da7e32095a03e926c951dbcc6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6172696e6173797374656d732f6c61726176656c2d6a736f6e2d726573706f6e73652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/arinasystems/laravel-json-response)[![Build Status](https://camo.githubusercontent.com/34e316aa1a8e11a8143dffd38c57937c2792afa479b911b249b258e1f5cad302/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6172696e6173797374656d732f6c61726176656c2d6a736f6e2d726573706f6e73652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/arinasystems/laravel-json-response)[![Quality Score](https://camo.githubusercontent.com/756362b2d5628c8e5d11cdb0af3e738a86af913ad8c2f34eccd2d424232d0a7c/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6172696e6173797374656d732f6c61726176656c2d6a736f6e2d726573706f6e73652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/arinasystems/laravel-json-response)[![Total Downloads](https://camo.githubusercontent.com/0f6d1bb04baa61eff246d86d6eae745a96a4da8d668fbe8c52e87aef17f73964/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6172696e6173797374656d732f6c61726176656c2d6a736f6e2d726573706f6e73652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/arinasystems/laravel-json-response)[![MIT Software License](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

Laravel JSON Response
=====================

[](#laravel-json-response)

Extensible and powerful API response package for Laravel.

- Localized Response
- Presets Response Status
- Attribute Builders
- Data Transformers
- JSON Exception Handler

---

- [Installation](#installation)
- [Basic Usage](#basic-usage)
- [Configuration](#configuration)
    - [Response Structure](#configuration)
    - [Preset Status](#preset-status)
    - [Data Transformers](#data-transformers)
    - [JSON Encoding Options](#json-encoding-options)
    - [Debugging Mode](#debugging-mode)
    - [Message Translations](#message-translations)

---

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

[](#installation)

You can install the package via composer:

```
composer require arinasystems/laravel-json-response
```

The package will automatically register its service provider.

You can optionally publish the config file with:

```
php artisan vendor:publish --tag="json-response:config"

```

---

Basic Usage
-----------

[](#basic-usage)

```
use ArinaSystems\JsonResponse\Facades\JsonResponse;

/**
 * Display a listing of products.
 *
 * @return \Illuminate\Http\Response
 */
public function index()
{
    $products = Product::paginate(2);

    return JsonResponse::json('ok', ['data' => ProductResource::collection($products)]);
}
```

With just one line of code, your API client will get this response:

```
{
    "success": true,
    "code": 200,
    "http_code": 200,
    "locale": "en",
    "message": "ok",
    "data": [
        {
            "id": "7OLgzrB1QVBQWMNZ3Rx08a24wAGEjqYVbeV",
            "name": "Aquafina Plastic Water Gallon – 18.9 L",
            "in_stock": true,
            "in_cart": false
            ...
        },
        {
            "id": "g3RbPoyMmPg9zr7qGZjW50Lp61aDlwnVOkE",
            "name": "Aquafina Plastic Water Bottle – 1.5 L",
            "in_stock": true,
            "in_cart": true
            ...
        }
    ],
    "additional": null,
    "links": {
        "first": "http://example.com/api/customer/products?page=1",
        "last": "http://example.com/api/customer/products?page=2",
        "prev": null,
        "next": "http://example.com/api/customer/products?page=2"
    },
    "meta": {
        "current_page": 1,
        "from": 1,
        "last_page": 2,
        "path": "http://example.com/api/customer/products",
        "per_page": "2",
        "to": 2,
        "total": 3
    }
}
```

---

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

[](#configuration)

You can customize the response configuration from `config/json-response.php` file.

```
