Laravel 流从 guzzle 请求下载 pdf 文件

Laravel streamDownload a pdf file from a guzzle request

我已经使用 Guzzle 和 Laravel 的 streamDownload() 设置了以下方法:

public function export(Request $request, string $uuid) 
{
    $api = $this->do_api;
    $client = new Client(['headers' => ['Authorization' => "Bearer {$this->do_token}"]]);
    return response()->streamDownload(function () use ($uuid, $api, $client) {
        $client->get("{$api}/customers/my/invoices/{$uuid}/pdf")->getBody();
    },"{$uuid}.pdf");
}

虽然我已确认此 API 确实 return 一个 PDF 文件,但 return 由 laravel 编辑的 PDF 有 0 个字节,我在做什么错了?

我在可调用函数中缺少 echo

$api = $this->do_api;
$client = new Client(['headers' => ['Authorization' => "Bearer {$this->do_token}"]]);
return response()->streamDownload(function () use ($uuid, $api, $client) {
    echo $client->get("{$api}/customers/my/invoices/{$uuid}/pdf")->getBody();
},"{$uuid}.pdf");