soloslee/json-response

JSON-API response for Laravel

v1.0.0 2017-02-14 02:33 UTC

This package is not auto-updated.

Last update: 2024-11-09 19:29:08 UTC


README

Installation

Install using composer:

composer require soloslee/json-response

Laravel (optional)

Add the service provider in config/app.php:

'Soloslee\JsonResponse\JsonResponseServiceProvider::class',

And add the JsonResponse alias to config/app.php:

'JsonResponse' => Soloslee\JsonResponse\Facades\JsonResponse::class,

Basic Usage

Start by creating an JsonResponse instance (or use the JsonResponse Facade if you are using Laravel):

use Soloslee\JsonResponse\JsonResponse;

return JsonResponse::success();

Success

JsonResponse::success([
    'id' => $user->id,
    'phone' => $user->phone,
    'email' => $user->email,
    'authorized' => $user->cleaner,
    'token' => $user->token
]);

Error

JsonResponse::error('Fails to send message.', 602);

License

Laravel Json Response is licensed under MIT license.