Skip to content

Commit 039fe17

Browse files
committed
fix: 系统事件重置或销毁
可以在这些事件中重置或销毁一些全局或静态的变量,也可以修改当前的请求和响应
1 parent 51f52fc commit 039fe17

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

laravel/app/Providers/EventServiceProvider.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ public function boot()
3333
{
3434
parent::boot();
3535

36-
//
36+
// 修改`app/Providers/EventServiceProvider.php`, 添加下面监听代码到boot方法中
37+
// 如果变量$events不存在,你也可以通过Facade调用\Event::listen()。
38+
// \Event::listen('laravels.received_request', function (\Illuminate\Http\Request $req, $app) {
39+
// $req->query->set('get_key', 'hhxsv5');// 修改querystring
40+
// $req->request->set('post_key', 'hhxsv5'); // 修改post body
41+
// });
42+
43+
// \Event::listen('laravels.generated_response', function (\Illuminate\Http\Request $req, \Symfony\Component\HttpFoundation\Response $rsp, $app) {
44+
// $rsp->headers->set('header-key', 'hhxsv5');// 修改header
45+
// });
3746
}
3847
}

0 commit comments

Comments
 (0)