1、RESPONSE篇
a.基本响应
基本的响应是路由闭包或者控制器动作中返回一个字符串,除了返回字符串,当返回数组,Eloquent时,laravel会将数组转化为json响应
b.返回相应对象
Route::get('home',function(){
//return response($content,$status)->header('key','value')
return response('hello world',200)->header('Content-Type','text/plain');
}):
c.为响应添加头信息
return response($content)
->header('Content-Type',$type)
->header('X-Header-one',$value)
->header('X-Header-two',$value);
也可以使用withHeaders指定添加的信息头数组
return response($content)->withHeaders([
'Content-Type' => $type,
'X-Header-one' => $value,
'X-Header-two' => $value
]);
d.为响应添加cookie
return response($content)->header('Content-Type',$type)->cookie(
laravel之http响应篇
最新推荐文章于 2024-07-06 05:17:56 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)