在laravel
中, 我们用request
来提取参数
那么怎么输出参数
我们可以用response
响应类,在controller
中我们要引入response
类
use IlluminateSupportFacadesResponse;
public function response(){
return response("hello the world")
->header('Content-Type', "text/html")
->cookie('name', 'value', 1);
return response("hello the world")
->header('Content-Type', "text/html")
->header('X-Header-One', 'Header Value')
->header('X-Header-Two', 'Header Value');
return response()->file(PUBLIC_PATH()."/1.jpg");
//下载
return response()->download(PUBLIC_PATH()."/1.jpg");
//跳转
return redirect()->away('https://www.baidu.com');
//跳转到别的类
return redirect()->action(
'IndexController@index', ['id' => 1]
);
return response('Hello World', 200)->header('Content-Type', 'text/plain');
$data = [ "msg"=>"test"];
//return response()->json($data);
return Response::json($data);
}
如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术
转载请注明:laravel中response响应类 出自老鄢博客 | 欢迎分享