laravel-csv-generator maintained by eugene-melbourne
Description
CSV export in laravel 5, 6, 7, 8, 9
Author
Last update
2022/08/09 01:28
(dev-master)
License
Downloads
14 139
LaravelCsvGenerator
Helps download *.csv files from your laravel project.
Installation
$ composer require eugene-melbourne/laravel-csv-generator
example of use in your controller
class MyController extends Controller
{
public function getCsv(): \Symfony\Component\HttpFoundation\StreamedResponse
{
$data = [
[1, 2.1],
[3, "hi, there"],
];
$headers = ['one', 'two'];
$data = array_merge([$headers], $data);
return (new \LaravelCsvGenerator\LaravelCsvGenerator())
->setData($data)
->renderStream();
}
set your own http headers with ->setHttpHeaders(array $httpHeaders)
get csv as string ->toString()
More examples in routes/web.php
Tested with Laravel 5.7, 5.8, 6.4