26/01
2017
Wallogit.com
2017 © Pedro Peláez
Middleware to force Laravel API group to JSON header
open-cetacean/laravel-json-header is a PHP package built for Laravel to force Laravel API group to JSON header activating wantsJson(), (*1)
This project can be installed via Composer. Add the following line to the require block of your composer.json file:, (*2)
{
"require": {
"open-cetacean/laravel-json-header": "^1.0"
}
}
You'll then run composer install or composer update., (*3)
Or run the following command:, (*4)
composer require open-cetacean/laravel-json-header
To register the middleware add the following to the $routeMiddleware array within the app/Http/Kernel.php file:, (*5)
protected $routeMiddleware = [
// ...
'acceptJson' => \OpenCetacean\JsonHeader\Middleware\AcceptJson::class,
// ...
];
then add the middleware to your API routes:, (*6)
Route::group(['middleware' => ['api', 'acceptJson']], function () {
// ...
}
The MIT License (MIT). Please see License File for more information., (*7)