Skip to content

Commit 0276a07

Browse files
committed
Add option to switch from lazy to cursor
1 parent 4850d2c commit 0276a07

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/Jobs/DataTableExportJob.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,15 @@ public function handle()
8181
)
8282
);
8383

84-
foreach ($dataTable->getFilteredQuery()->lazy() as $row) {
84+
if (config('datatables-export.method', 'lazy') === 'lazy') {
85+
$query = $dataTable->getFilteredQuery()->lazy(config('datatables-export.chunk', 1000));
86+
} else {
87+
$query = $dataTable->getFilteredQuery()->cursor();
88+
}
89+
90+
foreach ($query as $row) {
8591
$cells = collect();
86-
$columns->map(function (Column $column, $index) use ($row, $cells) {
92+
$columns->map(function (Column $column) use ($row, $cells) {
8793
$property = $column['data'];
8894
$value = Arr::get($row, $property, '');
8995

src/config/datatables-export.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@
44

55
return [
66

7+
/**
8+
* Method to use to iterate with the query results.
9+
* Options: lazy, cursor
10+
*
11+
* @link https://laravel.com/docs/eloquent#cursors
12+
* @link https://laravel.com/docs/eloquent#chunking-using-lazy-collections
13+
*/
14+
'method' => 'lazy',
15+
16+
/**
17+
* Count chunks to be used when using lazy method.
18+
*/
19+
'chunk' => 1000,
20+
721
/**
822
* Default export format for date.
923
*/

0 commit comments

Comments
 (0)