From 19ccc565d0a87eeac68b9a1902c1950ee49233cb Mon Sep 17 00:00:00 2001 From: Jimmy Setiawan Date: Wed, 25 Aug 2021 21:18:42 +0700 Subject: [PATCH] Add store() method to store report to disk for CSV, excel & pdf --- readme.md | 5 +++-- src/ReportMedia/CSVReport.php | 3 ++- src/ReportMedia/ExcelReport.php | 5 +++++ src/ReportMedia/PdfReport.php | 7 +++++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index ff76126..1fcfc1b 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,8 @@ # Laravel Report Generators (PDF, CSV & Excel) Rapidly Generate Simple Pdf Report on Laravel (Using [barryvdh/laravel-dompdf](https://github.com/barryvdh/laravel-dompdf) or [barryvdh/laravel-snappy](https://github.com/barryvdh/laravel-snappy)) or CSV / Excel Report (using [Maatwebsite/Laravel-Excel](https://github.com/Maatwebsite/Laravel-Excel)) -This package provides a simple pdf, csv & excel report generators to speed up your workflow +This package provides a simple pdf, csv & excel report generators to speed up your workflow. +It also allows you to stream(), download(), or store() the report seamlessly. ## Version | Version | Laravel Version | Php Version | Maatwebsite/Excel Ver | Feature @@ -86,7 +87,7 @@ public function displayReport(Request $request) 'Total Balance' => 'point' // if you want to show dollar sign ($) then use 'Total Balance' => '$' ]) ->limit(20) // Limit record to be showed - ->stream(); // other available method: download('filename') to download pdf / make() that will producing DomPDF / SnappyPdf instance so you could do any other DomPDF / snappyPdf method such as stream() or download() + ->stream(); // other available method: store('path/to/file.pdf') to save to disk, download('filename') to download pdf / make() that will producing DomPDF / SnappyPdf instance so you could do any other DomPDF / snappyPdf method such as stream() or download() } ``` diff --git a/src/ReportMedia/CSVReport.php b/src/ReportMedia/CSVReport.php index ac66df3..eb0231a 100755 --- a/src/ReportMedia/CSVReport.php +++ b/src/ReportMedia/CSVReport.php @@ -17,7 +17,8 @@ public function download($filename, $save = false) } if ($save) { - $csv = Writer::createFromPath($filename, 'w'); + $filePath = $filename; + $csv = Writer::createFromPath($filePath, 'w'); } else { $csv = Writer::createFromFileObject(new \SplTempFileObject()); } diff --git a/src/ReportMedia/ExcelReport.php b/src/ReportMedia/ExcelReport.php index 2288e48..334e913 100644 --- a/src/ReportMedia/ExcelReport.php +++ b/src/ReportMedia/ExcelReport.php @@ -66,6 +66,11 @@ public function make() return new ExportView($view); } + public function store($filePath, $customDisk = null){ + $export = $this->make(); + Excel::store($export, $filePath, $customDisk); + } + public function download($filename) { $export = $this->make(); diff --git a/src/ReportMedia/PdfReport.php b/src/ReportMedia/PdfReport.php index b4ab1ae..9772622 100644 --- a/src/ReportMedia/PdfReport.php +++ b/src/ReportMedia/PdfReport.php @@ -55,4 +55,11 @@ public function download($filename) { return $this->make()->download($filename . '.pdf'); } + + public function store($filePath) + { + $content = $this->make()->download()->getOriginalContent(); + + \Storage::put($filePath, $content); + } }