文档:响应

文档:响应

响应

php
 
app('response')->send()
1

设置响应状态码

response()->statusCode(int $code, string $statusText = '')

设置响应头

response()->header(string $key, $value)

设置Cookie

response()->cookie(string $key, string $value = '', int $expire = 0, string $path = '/', string $domain = '', bool $secure = false, bool $httpOnly = true)

响应json

response()->json($data)

响应xml

response()->xml($data)

响应html

response()->html($data)

响应文本

response()->str($data)

响应下载文件

可以设置下载速度,支持断点续传

response()->file(File $file, int $speed = 512)

响应图片

response()->image(Image $image)

例如:输出二维码

php
      
use Zodream\Image\QrCode;

$image = new QrCode();
$image->encode('zodream');
return response()->image($image);
123456

重定向

response()->redirect($url, int $time = 0)

响应自定义导出文件

response()->export(ExportObject $expert)

例如:导出excel

php
        
use Zodream\Html\Excel\Exporter;

$export = new Exporter('流水记录', [
            'id' => 'ID',
            'type' => '类型',
            'money' => '金额',
        ], LogModel::query());
response()->export($export)
12345678

允许跨域

response()->allowCors()