Laravel Json Response
Ethereal Package
AnEasy way to implement API formatted json responses.
Format:
{
"data": {...},
"errors": [],
"success": true,
"status_code": 200,
"token": null
}
Setup
Install:
composer require Faridibin/laravel-json-response
Add the service provider to your app config:
\Faridibin\LaravelJsonResponse\Providers\LaravelJsonResponseProvider::class,
Add the middleware to your app\Http\Kernel.php
Either:
// Formats all responses in json. Catches errors listed in config and JsonResponseErrorExceptions
Faridibin\LaravelJsonResponse\Middleware\OutputJsonResponse,
// Extends the OutputJsonResponse to catch all errors, to keep the JSON output
Faridibin\LaravelJsonResponse\Middleware\CatchAllExceptions,
Config
Publish the config by using the command:
php artisan vendor:publish