Use the stream()
method to send a file to the browser without triggering a download.
If you want to return file content without initiating a download, you can use the stream()
method. It will display the file in the browser.
// It returns a PDF as a binary string
$pdf = ThirdPartyApp::pdf ($id);
$headers = ['Content-Type' => 'application/pdf'];
return response()->stream (function () use ($pdf) {
echo $pdf;
}, Response::HTTP_OK, $headers);
PHP