| Package Data | |
|---|---|
| Maintainer Username: | lucandrade |
| Maintainer Contact: | lucas.andrade.oliveira@hotmail.com (Lucas Andrade de Oliveira) |
| Package Create Date: | 2015-09-06 |
| Package Last Update: | 2021-11-22 |
| Home Page: | |
| Language: | PHP |
| License: | MIT |
| Last Refreshed: | 2025-10-30 03:12:07 |
| Package Statistics | |
|---|---|
| Total Downloads: | 752 |
| Monthly Downloads: | 0 |
| Daily Downloads: | 0 |
| Total Stars: | 2 |
| Total Watchers: | 2 |
| Total Forks: | 1 |
| Total Open Issues: | 1 |
Standard API response to use with Laravel Framework
Laravel | PHP :---------|:---------- 5.0.x | >= 5.4 5.1.x | >= 5.5.9
Add the following line to your composer.json file:
"lucasandrade/laravel-apiresponse": "dev-master"
Then run composer update to get the package.
Add this line of code to the providers array located in your config/app.php file:
Lucandrade\ApiResponse\ApiResponseServiceProvider::class,
Add this line to the aliases array:
'ApiResponse' => Lucandrade\ApiResponse\Facades\ApiResponse::class,
Run the vendor:publish command:
php artisan vendor:publish
Execute this command from your project path:
cp ./vendor/lucasandrade/laravel-apiresponse/src/config/apiresponse.php ./config
Uncomment the following line of your bootstrap/app.php file:
\\ $app->withFacades();
Add this line in the end of file:
$app->register(Lucandrade\ApiResponse\Lumen\ApiResponeServiceProvider::class);
Route::get('/api-response', function() {
return ApiResponse::setPayload("Here's data")
->setStatusMessage("OK")
->setRequestCode(0)
->get();
});
Output:
{
"status":true,
"payload":"Here's data",
"message":"OK",
"completed_at":"2015-09-02 16:27:11",
"code":0
}
To change response fields alter apiresponse.php file located in your config directory:
return [
"keys" => [
"status" => "{statusNameField}",
"status_message" => "{messageNameField}",
"request_code" => "{codeNameField}",
"payload" => "{payloadNameField}",
"time" => "{completedAtNameField}"
]
];
Note: remember to add
use ApiResponse;to the beginning of the yours class file