laravel中response响应类

发布时间:2020-11-23 23:26:08 阅读:1028次

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加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询

转载请注明:laravel中response响应类 出自老鄢博客 | 欢迎分享