diff --git a/src/Concerns/Exportable.php b/src/Concerns/Exportable.php index cf635f5..f1044d0 100644 --- a/src/Concerns/Exportable.php +++ b/src/Concerns/Exportable.php @@ -55,6 +55,16 @@ public function download(?string $filename = null): StreamedResponse return CsvExporter::download($this, $this->getFilename($filename)); } + /** + * @param bool $asString + * + * @return mixed + */ + public function stream(bool $asString = false): mixed + { + return CsvExporter::stream($this, $asString); + } + /** * @param string|null $filename * @param string|null $disk diff --git a/src/CsvExporter.php b/src/CsvExporter.php index eb6dc4e..8fa07a2 100644 --- a/src/CsvExporter.php +++ b/src/CsvExporter.php @@ -85,6 +85,23 @@ public function download(object $exportable, string $filename): StreamedResponse return $this->service->download($exportable, $filename); } + /** + * @param object $exportable + * @param bool $asString + * + * @throws InvalidCellValueException + */ + public function stream(object $exportable, bool $asString = false) + { + $streamResponse = $this->service->stream($exportable); + + if ($asString) { + return stream_get_contents($streamResponse); + } + + return $streamResponse; + } + /** * @param object $exportable * @param string $filename diff --git a/src/Services/ExportableService.php b/src/Services/ExportableService.php index 22f7a7d..5eddbb9 100644 --- a/src/Services/ExportableService.php +++ b/src/Services/ExportableService.php @@ -119,6 +119,16 @@ function () use ($stream) { ); } + /** + * @param object $exportable + * + * @throws InvalidCellValueException + */ + public function stream(object $exportable) + { + return $this->getStream($exportable); + } + /** * @param object $exportable * @param string $filename