Download the PHP package codebot/laravel-response-builder without Composer
On this page you can find all versions of the php package codebot/laravel-response-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download codebot/laravel-response-builder
More information about codebot/laravel-response-builder
Files in codebot/laravel-response-builder
Package laravel-response-builder
Short Description Simple package for Laravel framework to standardize the structure of JSON responses.
License MIT
Informations about the package laravel-response-builder
About
Package codebot/laravel-response-builder
is a simple package for Laravel framework to standardize the structure of JSON responses.
You will find this package helpful if you need your responses to look like this:
or
Installation
For Laravel 5.4 and versions below add \Rb\Core\RbServiceProvider::class
to providers in config/app.php file.
Next run the command below in your console:
Requests
Once you published vendor, you should see App\Http\Requests\Rb\RbRequest class
. This will be base class for
laravel-response-builder's requests.
To generate a request that extends RbRequest, run:
If you are using Laravel's Validator class, you can use Rb\Core\RbValidator
to standardize the structure of failed response.
RbValidator::validate() method checks if the validation fails and throws Illuminate\Http\Exceptions\HttpResponseException with the standardized json response structure.
Usage
All setters are fluent, so example above could be written like:
Package contains HttpStatusCode class with http status codes defined.
The Facade
The package contains a facade class in case if you don't want to interact with all of these setters.
$data
and $errors
variables are arrays and are optional.
Configuration
Once you have vendor published, you should see config/response_builder.php
file.
request_path - Generated request classes will be stored in specified directory.
request_namespace - Namespace for generated request class.
is_authorize - Default value of Request's authorize() method.
messages - Contains messages for Response's "message" field.
messages.failed_validation - Default message for response that failed the validation.
Fields
status
- boolean (Not Nullable)
status_code
- integer (Not Nullable)
message
- string (Nullable)
data
- array (Not Nullable, can be empty)
errors
- array (Not Nullable, can be empty)