diff --git a/src/ReportGenerator.php b/src/ReportGenerator.php index 93a186c..cbf4152 100644 --- a/src/ReportGenerator.php +++ b/src/ReportGenerator.php @@ -29,7 +29,7 @@ public function __construct() $this->applyFlush = (bool) Config::get('report-generator.flush', true); } - public function of($title, Array $meta = [], $query, Array $columns) + public function of($title, Array $meta, $query, Array $columns) { $this->headers = [ 'title' => $title, diff --git a/src/ReportMedia/CSVReport.php b/src/ReportMedia/CSVReport.php index c9fa1db..ac66df3 100755 --- a/src/ReportMedia/CSVReport.php +++ b/src/ReportMedia/CSVReport.php @@ -10,13 +10,17 @@ class CSVReport extends ReportGenerator { protected $showMeta = false; - public function download($filename) + public function download($filename, $save = false) { if (!class_exists(Writer::class)) { throw new Exception('Please install league/csv to generate CSV Report!'); } - $csv = Writer::createFromFileObject(new \SplTempFileObject()); + if ($save) { + $csv = Writer::createFromPath($filename, 'w'); + } else { + $csv = Writer::createFromFileObject(new \SplTempFileObject()); + } if ($this->showMeta) { foreach ($this->headers['meta'] as $key => $value) { @@ -48,7 +52,14 @@ public function download($filename) $ctr++; } - $csv->output($filename . '.csv'); + if (!$save) { + $csv->output($filename . '.csv'); + } + } + + public function store($filename) + { + $this->download($filename, true); } private function formatRow($result) @@ -77,4 +88,4 @@ private function formatRow($result) return $rows; } -} \ No newline at end of file +}