Download the PHP package chuoke/response4laravel without Composer
On this page you can find all versions of the php package chuoke/response4laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download chuoke/response4laravel
More information about chuoke/response4laravel
Files in chuoke/response4laravel
Package response4laravel
Short Description A response helper for Laravel.
License MIT
Homepage https://github.com/chuoke/response4laravel
Informations about the package response4laravel
A API response helper for Laravel.
This Laravel package can halp organize uniform response data format for API. It is designed to be able to parse all types of data, including API Resource, Collection, and Paginator. And you can custom it.
Installation
You can install the package via composer:
Usage
Import response object
To enable uniform response, we typically define an BaseController
and create a helper method for uniform response.
First, in the BaseController
use the helper trait, there is a response
method that returns the Chuoke\Response4Laravel\Response
instance object.
By the way, more helper methods will be added in the future, depending on the situation.
Or make a helper method you want. In this way, it is easy to customize the response object parameters, as detailed examples are shown later.
Next, you can use it in your controller.
General Usage
According to the general case, shortcut methods are defined for only the most frequently used states.
See the code for more details, create custom response classes if they are missing what you need, or please submit a PR if there are more general methods that need to be added.
Response Resource
Single resource
By default, the data
will not exist if the resource dont use wrap.
Collection resource
The data
always exists.
And you can customize the data
key.
The data wrapper uses first value defined in the response class, and then uses of resource. If neither is defined, then the single resource will not wrapped, but the collection is always wrapped. The default key name is
data
, can set diffrent value for single data and collection.
Paging Response
Customize Response
In many cases, we're used to having a consistent format for our response data.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- chuoke
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of response4laravel with dependencies
illuminate/contracts Version ^9.0
spatie/laravel-package-tools Version ^1.14.0
symfony/http-foundation Version ^6.2