企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 中间件前 如果我们想在请求处理前执行业务逻辑,则在$next闭包执行前执行业务逻辑操作 ~~~ public function handle($request, Closure $next) { // 执行业务逻辑操作 //1.先执行我们自定义逻辑 return $next($request); // 2.后执行$next() } ~~~ # 中间件后 如果想要在请求处理后执行中间件业务逻辑,则在$next闭包执行后执行操作: ~~~ public function handle($request, Closure $next) { $response= $next($request); // 1.先$next() // 执行动作 // 2.执行我们自定义逻辑 //可以把这个打印出来 //dd($response); //echo $response; return $response; // 3.返回$next()之前的结果 } ~~~