fasberg / prettyresponse
A helper for creating pretty api responses or just wrapping resources
v1.0.6
2019-09-14 08:41 UTC
Requires
- php: >=7.1.3
- laravel/framework: ~5.8.0|^6.0
This package is not auto-updated.
Last update: 2024-05-19 09:33:32 UTC
README
Installation
composer require fasberg/prettyresponse
Usage
use Fasberg\PrettyResponse\Facade\PrettyResponseFacade as PrettyResponse;
...
return PrettyResponse::wrap($resource, $options);
return PrettyResponse::conditional($condition, $resource, $options);
Wrap
Will take an array, collection or resource and wrap it in the base success response
Conditional
Conditional variable can be boolean, Closure or Collection.
It will default to trying to convert input into a boolean.
Data should be in the form of an array, collection or resource.
Options allows you to set a custom error/success message and return code
$options = [
'error' => [
'message' => 'My error message',
'code' => 123
],
'success' => [
'message' => 'My success message',
'code' => 321
]
];
Configuration
There is a configuration file available that will allow you to set global defaults.
Publish it by running
php artisan vendor:publish --provider="Fasberg\PrettyResponse\PrettyResponseServiceProvider"