An open API service indexing awesome lists of open source software.

https://github.com/lzyim/json-response

JSON-API response for Laravel
https://github.com/lzyim/json-response

json-response laravel

Last synced: 2 months ago
JSON representation

JSON-API response for Laravel

Awesome Lists containing this project

README

          

Json Response
=====

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

Install using composer:

```bash
composer require soloslee/json-response
```

Laravel (optional)
------------------

Add the service provider in `config/app.php`:

```php
'Soloslee\JsonResponse\JsonResponseServiceProvider::class',
```

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

```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):

```php
use Soloslee\JsonResponse\JsonResponse;

return JsonResponse::success();
```

### Success

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

### Error

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

## License

Laravel Json Response is licensed under [MIT license](http://opensource.org/licenses/MIT).