File tree Expand file tree Collapse file tree 1 file changed +23
-2
lines changed
Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -403,8 +403,9 @@ public function response(callable $callback)
403403 public function excel ()
404404 {
405405 $ ext = '. ' . strtolower ($ this ->excelWriter );
406+ $ callback = $ this ->fastExcel ? $ this ->fastExcelCallback () : $ this ->excelWriter ;
406407
407- return $ this ->buildExcelFile ()->download ($ this ->getFilename () . $ ext );
408+ return $ this ->buildExcelFile ()->download ($ this ->getFilename () . $ ext, $ callback );
408409 }
409410
410411 /**
@@ -536,8 +537,9 @@ private function toColumnsCollection(array $columns)
536537 public function csv ()
537538 {
538539 $ ext = '. ' . strtolower ($ this ->csvWriter );
540+ $ callback = $ this ->fastExcel ? $ this ->fastExcelCallback () : $ this ->csvWriter ;
539541
540- return $ this ->buildExcelFile ()->download ($ this ->getFilename () . $ ext );
542+ return $ this ->buildExcelFile ()->download ($ this ->getFilename () . $ ext, $ callback );
541543 }
542544
543545 /**
@@ -685,4 +687,23 @@ protected function convertToLazyCollection($collection)
685687
686688 return $ collection ;
687689 }
690+
691+ /**
692+ * @return \Closure
693+ */
694+ public function fastExcelCallback ()
695+ {
696+ $ columns = $ this ->exportColumns ();
697+
698+ $ callback = function ($ row ) use ($ columns ) {
699+ $ mapped = [];
700+ foreach ($ columns as $ column ) {
701+ $ mapped [$ column ['title ' ]] = $ row [$ column ['data ' ]];
702+ }
703+
704+ return $ mapped ;
705+ };
706+
707+ return $ callback ;
708+ }
688709}
You can’t perform that action at this time.
0 commit comments