lumen中间件 Middleware
app/http 下新建 TestMiddleware.php <?php namespace App\Http\Middleware; use Closure; class TestMiddleware { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $params = $request->all(); if(empty($params['id'])){ $response = ['code'=>400,'msg'=>'参数错误','data'=>[]]; return response()->json($response); } return $next($request); } } bootstrap/app.php里面启用 $app->routeMiddleware([ //'auth' => App\Http\Middleware\Authenticate::class, 'test'=>App\Http\Middleware\TestMiddleware::class ]);