Download the PHP package farhanwazir/makeresponse without Composer
On this page you can find all versions of the php package farhanwazir/makeresponse. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download farhanwazir/makeresponse
More information about farhanwazir/makeresponse
Files in farhanwazir/makeresponse
Package makeresponse
Short Description Make Response Schema Responder.
License MIT
Informations about the package makeresponse
Make Response
This PHP library helps to generate global standard response in JSON
and Array
for client (API Client, POS Client, Web Client etc). It is not framework dependent, you are open to use it with any PHP project.
Why to use this library
- This library is a standard formatted schema to response, you don't need to make a document for every web service, just refer to this.
- This library works logically, you must respect standards.
- It is framework free and if you want it to use with any framework then you can. It has Laravel & Lumen build-in support as described below.
Installation
Via composer command
Or add below line in your composer.json and run composer update
command
Laravel & Lumen Configuration
Laravel user's
For Laravel user's can add below line in config/app.php
Do not close config/app, go down inside "aliases"
Lumen user's
For Lumen user's can add below line in bootstrap/app.php
Add alias as facade in laravel
Usage
You just need to call makeResponse()
helper function to respond to request. Below listed available methods will help you to explorer MakeResponse.
setStatus(numeric)
set numeric value with positive or negativesetMessage(string)
set string message not big string, it is for short messagesetErrors(sting|array)
set string or array for errorssetResult(string|array)
set string or array for result parameter of your response-
set(status, result, errors, message)
set method for set response parameters once get()
get formatted response collectionget()->toArray()
convert collection in arrayget()->toJson()
convert collection in json
Use via helper function
$status
must be numeric positive or negative.$result
string or array.Default null
$errors
string or array.Default null
$message
one line string.Default null
$array
boolean, it is belongs to returning response (in array or json).Default true
Get response example
Example 1: Get formatted response in array
Example 2: Get formatted response in json
Example 3: Verify formatted response to client
Example 4: Convert response in array
Example 5: Direct class call approach
Laravel and Lumen user's
You can also use above illustrated example and below is for Laravel and Lumen style: