therour / your-json-response
modifier for json response skeleton
0.0.3
2018-11-02 10:42 UTC
Requires
- php: >=7.0
This package is auto-updated.
Last update: 2024-04-29 03:57:09 UTC
README
INSTALLATION
via Composer
composer require therour/your-json-response
For Laravel 5.4 and below Add Service Provider to config/app.php
of your laravel project
'providers' => [ ... Therour\YourJsonResponse\ServiceProvider::class, ]
CONFIGURATION
publish configuration file
php artisan vendor:publish --provider=Therour\YourJsonResponse\ServiceProvider
the configuration file is located at your laravel's config directory by name yjresponse.php
USAGE
this package is bundled with named skeleton ok
, you can edit the skeleton in config yjresponse.php
return response()->ok($data, $message = 'success', $code = 200); // or return response()->yourNamedSkeleton($data, $message = 'success', $code = 200);
CREATING SKELETON
open configuration file yjresponse.php
use code
, message
, data
, type
, and meta_page
as value of skeleton to place it
EG:
'skeleton' => [ ... // 'created' is the name of skeleton, and its value is the skeleton 'created' => [ 'status' => [ 'code', 'message' ], 'result' => 'data' ] ],
at the same file, also define the default value
'defaults' => [ ... 'created' => [ 'code' => 201, 'message' => 'Succesfully create the object' ] ]
Use your custom skeleton
return response()->created($product);
result
{ "status": { "code": 201, "message": "Succesfully create the object" }, "result": { "name": "Product X", "price": 6000, "weight": 500 } }