Skip to content

Commit

Permalink
Add store() method to store report to disk for CSV, excel & pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimmy-JS committed Aug 25, 2021
1 parent 6130ad1 commit 19ccc56
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
5 changes: 3 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
}
```

Expand Down
3 changes: 2 additions & 1 deletion src/ReportMedia/CSVReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
5 changes: 5 additions & 0 deletions src/ReportMedia/ExcelReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions src/ReportMedia/PdfReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 19ccc56

Please sign in to comment.