Package Data | |
---|---|
Maintainer Username: | igorsgm |
Maintainer Contact: | igor.sgm@gmail.com (Igor Moraes) |
Package Create Date: | 2021-03-08 |
Package Last Update: | 2021-03-08 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-17 03:08:48 |
Package Statistics | |
---|---|
Total Downloads: | 8 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
ApiResponse
Middleware to set the Accept: application/json
header to your api routes and also throw exceptions as
JSON.response()->success(...)
_ide_helper_macros.php
file generated to improve your IDE's code completioncomposer require igorsgm/laravel-api-responses
php artisan vendor:publish --provider="Igorsgm\LaravelApiResponses\LaravelApiResponsesServiceProvider"
First, register the ApiResponse
at the top of your api middleware group, inside app/Http/Kernel.php
.
class Kernel extends HttpKernel
{
protected $middlewareGroups = [
// ...
'api' => [
\Igorsgm\LaravelApiResponses\Http\Middleware\ApiResponse::class,
// ...
],
];
// ...
}
Now simply start using one of the available response functions to always return a normalized API data inside your controllers.
response()->success($data, $message) // ($data = [], $message = '', $status = 200, $headers = [])
response()->successMessage($message) // ($message = '', $status = 200, $headers = [])
response()->error($errors) // ($errors = [], $message = '', $status = 500, $headers = [])
response()->errorMessage($message) // ($message = '', $status = 500, $headers = [])
response()->exceptionError($exception) // ($exception, $message = '', $status = 0, $headers = [])
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.