我有一个api路由组,我想在其中使用多个中间件类,但是,Laravel似乎完全无视我的其他中间件:
// API ROUTE
Route::group(['prefix' => 'auth', 'middleware' => ['auth:api', 'additional']], function () {
Route::post('api/route', 'apiController@index');
});
// REGISTER ADDITIONAL MIDDLEWARE IN KERNEL
protected $routeMiddleware = [
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
...
'additional' => \App\Http\Middleware\Additional::class
];
// ADDITIONAL MIDDLEWARE CLASS
class Additional
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
return Log::info($request);
// return $next($request);
}
}
如您所见,在中间件类中,我希望注销$request
,并且还注释掉$next
函数,但是我的应用程序无视此并显示主视图...