Download the PHP package rohan0793/jsend without Composer
On this page you can find all versions of the php package rohan0793/jsend. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package jsend
jsend
This is a simple composer package to issue JSend responses from a Laravel 5 application.
To read about JSend, go through this guide
Installation
Require the package through composer:
composer require rohan0793/jsend
Add the service provider to the provider's array in your app.php config file:
RC\JSend\ResponseMacroServiceProvider::class,
Basic Example
Output:
Resource Fetched Example
Output:
The resource fetched macro is defined for ease and readability. It is calling the underlying JSend macro itself. The message, status and code will be filled automatically as success
, Resource Fetched Successfully
, and 200
respectively. This can useful in removing duplicated code when you have many routes for fetching different resources.
Resource Updated Example
Similar to resource_fetched
we have resource updated
. The message, status and code will be filled automatically as success
, Resource Updated Successfully
, and 200
respectively.
Resource Created Example
Similar to resource_fetched
we have resource_created
. The message, status and code will be filled automatically as success
, Resource Created Successfully
, and 201
respectively.
Resource Deleted Example
The resource_deleted
is a little special. It will output code 204 No Content
. According to HTTP code specifications, it will have no output at all.
JSend Error Example
Finally, we have the jsend_error
macro which is basically used to respond when there has been an error. It takes an exception as the first argument. It will output code and message from the exception itself. If custom message and code is passed, they will be output instead.
Presenter
Other than the basic response macros with messages and codes, this package also supports presenters. You can build your own presenters. The package will automatically call the present()
method on the presenter passed. The recommended approach is using Fractal Package from The PHP League. This package provides very powerful data transforming and presenting capabilities. The documentation is extensive and easy to read and understand.