Skip to content

Commit 973e91d

Browse files
committed
Use lazy() when getting Export results
1 parent 22ddf48 commit 973e91d

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/Export/Jobs/ExportToCsv.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)