I'm using: Laravel Framework version 5.1.24 (LTS), and I am having great difficulty with implementing a Middleware route group.
Here is what I have in my routes.php:
Route::group(['middleware' => 'api'], function () {
Route::get('api/users', 'UserController@getUsers');
Route::get('api/user/{id}', 'UserController@viewUser');
Route::post('api/user', 'UserController@addUser');
Route::put('api/user/{id}', 'UserController@updateUser');
Route::delete('api/user/{id}', 'UserController@deleteUser');
});
I've also added this to the $routeMiddleware array within Kernel.php:
'api' => \App\Http\Middleware\ApiAuthenticate::class,
I have the ApiAuthtenticate Middleware set to run before continuing, so I'm expecting to see the error handling I have in there, but I am not. What I do get is the MethodNotAllowedHttpException exception thrown.
The strange thing is if I remove the Middleware route group, and add the ApiAuthenticate class to the $middleware array within Kernel.php, it behaves exactly as it should (throws my Exceptions). However, I want to use the Middleware on a specified group of routes, not on the entire global scope.
Can someone please help?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire