Download the PHP package rezky/laravel-response-formatter without Composer
On this page you can find all versions of the php package rezky/laravel-response-formatter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-response-formatter
LARAVEL RESPONSE FORMATTER
This package is made so that every response that is returned has the same format.
HOW TO INSTALL
there are several steps you have to do in order to use it properly
Install Package
do the installation with
Add Service Provider
add provider in file
Publish Config
publish config with command php artisan vendor:publish --provider="Rezky\LaravelResponseFormatter\LaravelResponseFormatterServiceProvider::class" --tag="config"
\
after published the config will be in
Customize Config
if you want to change the code, do it in you can add code and group or reduce code and group
code
- internal code list, not http code\
group
- internal grouping of code against http code
once added, you must convert the list to constant with the command so that it can be used\
php artisan code:create
\
constant will be in Rezky\LaravelResponseFormatter\Http\Response
example config
CODE_SUCCESS
- key label\
000
- internal code
key label must prefixed with CODE_
and is in one of the groups. otherwise default with http code 500
End
package ready to use
Example
Throw Error
If throw error is used, the program will stop on that line and return an error message
it will return
Return Response
it will return
response support
class support | return |
---|---|
\Illuminate\Database\Eloquent\Model | data => array |
|
\Illuminate\Support\Collection | data => array |
|
\Illuminate\Pagination\LengthAwarePaginator | data => array with paginator |
|
\Illuminate\Http\Resources\Json\JsonResource | data => array /object and with/without paginator |
Format List
field data
following $data
format
Default Format
With Paginator
EXCEPTION HANDLER
in the config, there is an override handler parameter. if it is changed to true, then every error covered in the case will be returned according to the format. there is config
\ the classes to be converted into the format :
Illuminate\Database\QueryException
Illuminate\Validation\ValidationException
Illuminate\Auth\AuthenticationException
Illuminate\Database\Eloquent\ModelNotFoundException
\ArgumentCountError
\Error
HttpException