File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -33,9 +33,11 @@ public function __construct(
3333 */
3434 public function handle (): void
3535 {
36- $ items = $ this ->processor ->query ()->forPage ($ this ->page , $ this ->perPage )->get ();
36+ $ items = $ this ->processor ->query ()
37+ ->lazy ()
38+ ->forPage ($ this ->page , $ this ->perPage );
3739
38- if (empty ( $ items )) {
40+ if ($ items-> isEmpty ( )) {
3941 return ;
4042 }
4143
@@ -46,18 +48,17 @@ public function handle(): void
4648 $ csvPath = $ this ->storagePath ($ fileName );
4749 $ csvWriter = SimpleExcelWriter::create ($ csvPath , 'csv ' );
4850
49- $ items -> each ( function ($ item ) use ( $ csvWriter ) {
51+ foreach ($ items as $ item ) {
5052 $ item = $ this ->processor ->formatRow ($ item );
5153
52- // Convert arrays inside $data to strings
5354 foreach ($ item as $ key => $ value ) {
5455 if (is_array ($ value )) {
5556 $ item [$ key ] = json_encode ($ value );
5657 }
5758 }
5859
5960 $ csvWriter ->addRow ($ item );
60- });
61+ }
6162
6263 $ csvWriter ->close ();
6364 }
You can’t perform that action at this time.
0 commit comments