月光 4年前

修改理由:

添加了官方文档中最新的一段

详细描述:

把 Cache Control Middleware 那一段翻译了加进文档里了,原文位置:https://learnku.com/docs/laravel/5.8/responses#attaching-headers-to-responses

相关信息:


此投稿状态为 标记为已读

内容修改:

红色背景 为原始内容

绿色背景 为新增或者修改的内容

OldNewDifferences
1  
21# HTTP 响应
32
43- [创建响应](#creating-responses)
 
6564                   'X-Header-One' => 'Header Value',
6665                   'X-Header-Two' => 'Header Value',
6766               ]);
 67             
 68<a name="cache-control-middleware"></a>  
 69#### 缓存控制中间件  
 70  
 71Laravel 内置了一个 `cache.headers` 中间件,可以用来快速为路由组设置 `Cache-Control`。如果在指令集中声明了 `etag`,则 Laravel 会自动把 ETag 标识符设置为响应内容的 MD5 哈希值。  
 72  
 73   Route::middleware('cache.headers:public;max_age=2628000;etag')->group(function() {  
 74       Route::get('privacy', function () {  
 75           // ...  
 76       });  
 77  
 78       Route::get('terms', function () {  
 79           // ...  
 80       });  
 81   });  
6882
6983<a name="attaching-cookies-to-responses"></a>
7084#### 添加 Cookies 到响应
 
149163       return $this->slug;
150164   }
151165
152 
 166
153167
154168<a name="redirecting-controller-actions"></a>
155169### 跳转到控制器 Action
 
254268
255269   return response()->file($pathToFile, $headers);
256270
257 
 271
258272
259273<a name="response-macros"></a>
260274## 响应宏