hoangdo / laravel-json-api
The Json Response formatter library for laravel
v0.1.0
2023-07-22 12:17 UTC
Requires
- php: ^8.0|^8.1|^8.2
- illuminate/broadcasting: ^v8.0|^v9.0|^v10.0
- illuminate/config: ^v8.0|^v9.0|^v10.0
- illuminate/console: ^v8.0|^v9.0|^v10.0
- illuminate/http: ^v8.0|^v9.0|^v10.0
- illuminate/routing: ^v8.0|^v9.0|^v10.0
- illuminate/support: ^v8.0|^v9.0|^v10.0
- illuminate/validation: ^v8.0|^v9.0|^v10.0
Requires (Dev)
- laravel-zero/foundation: ^v8.0|^v9.0|^v10.0
README
A library that will help you format the response easily
Installation
composer require hoangdo/laravel-json-api
Usage
Just normal use it as a middleware
// web.php Route::get('foo', 'FooController@index')->middleware('json'); // or Route::middleware('json')->group(function () { Route::get('foo', 'FooController@index'); Route::get('bar', 'BarController@index'); })
If you want to use it global for all api, just add it to the api
group middleware
// app/Http/Kernel.php ... protected $middlewareGroups = [ ... 'api' => [ // Add it here 'json', 'throttle:60,1', \Illuminate\Routing\Middleware\SubstituteBindings::class, ], ... ]; ...
If you want to change the middleware alias name, for avoid conflict with another libraries, just fix it by .env
# You can add multiple aliases, separated by "," JSON_MIDDLEWARE_NAME=json1,json2