Last active
December 25, 2023 23:35
-
-
Save btxtiger/902d2742112a29d7ca5bb655b0d0eaaf to your computer and use it in GitHub Desktop.
Laravel download CSV string as file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$csv = \App\Services\DataExportService::createCsvExport(); | |
$BOM = "\xEF\xBB\xBF"; | |
return response()->streamDownload( | |
function () use ($BOM, $csv) { | |
echo $BOM . $csv; | |
}, | |
'data-export.csv', | |
[ | |
'Content-Type' => 'application/octet-stream', | |
'Content-Disposition' => 'attachment; filename="data-export.csv', | |
'Content-Encoding: UTF-8', | |
], | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment