浅析Laravel 中Kernel.php中 中间件的作用

中间件的分类

$middleware

protected $middleware = [
        //Laravel 5 维护模式以及白名单
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
        //验证 post 数据大小
        \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
        //去除首尾空白字符
        \App\Http\Middleware\TrimStrings::class,
        //转换空字符串为 null
        \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
        //https://laravel-china.org/docs/laravel/5.5/requests/1297#76f110
        \App\Http\Middleware\TrustProxies::class,
    ];

$middlewareGroups

因为我项目是Api,所以这个里面的中间件我全部都取消了

$routeMiddleware

protected $routeMiddleware = [
        'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
        'can' => \Illuminate\Auth\Middleware\Authorize::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
    ];