Download the PHP package gelgoog135/laravel-jsend without Composer
On this page you can find all versions of the php package gelgoog135/laravel-jsend. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gelgoog135/laravel-jsend
More information about gelgoog135/laravel-jsend
Files in gelgoog135/laravel-jsend
Package laravel-jsend
Short Description Laravel helpers to easily send JSend-compliant responses
License MIT
Homepage http://shalvah.me/laravel-jsend
Informations about the package laravel-jsend
laravel-jsend
Simple helpers to generate JSend-compliant responses for your Laravel app
The JSend specification lays down some rules for how JSON responses from web servers should be formatted. JSend is especially suited for REST-style applications and APIs.
Installation
Laravel 7 and above:
Laravel 5.1 - 6.*:
Usage
In your controller:
You can also add the JsendExceptionFormatter trait in App\Exceptions\Handler to format JSON responses for unhandled exceptions and Laravel validation errors as JSend:
Available helpers
jsend_success
The jsend_success function creates a JSend success response instance.
Generates a response:
You may pass an Eloquent model instead of an array as the "data" object:
jsend_fail
The jsend_fail function creates a JSend fail response instance.
Generates a response:
jsend_error
The jsend_error function creates a JSend error response instance.
Generates a response:
You may also pass optional code and data objects.
Generates a response:
Note: for each helper, the HTTP status codes are set automatically (to 200, 400, and 500 for
success,fail, anderrorrespectively), and the headerContent-type: application/jsonis set. If you wish, you may specify a HTTP status code and additional headers as the last two parameters.
License
MIT