Skip to content

Commit ff2ee56

Browse files
committed
Use LazyCollection to handle bigger data sets
1 parent fd189e0 commit ff2ee56

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/SelectTree.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
2121
use Illuminate\Support\Arr;
2222
use Illuminate\Support\Collection;
23+
use Illuminate\Support\LazyCollection;
2324
use InvalidArgumentException;
2425

2526
class SelectTree extends Field implements HasAffixActions
@@ -85,7 +86,7 @@ class SelectTree extends Field implements HasAffixActions
8586

8687
protected bool $storeResults = false;
8788

88-
protected Collection|array|null $results = null;
89+
protected LazyCollection|array|null $results = null;
8990

9091
protected Closure|bool|null $multiple = null;
9192

@@ -179,8 +180,8 @@ protected function buildTree(): Collection
179180
$nonNullParentQuery->withTrashed($this->withTrashed);
180181
}
181182

182-
$nullParentResults = $nullParentQuery->get();
183-
$nonNullParentResults = $nonNullParentQuery->get();
183+
$nullParentResults = $nullParentQuery->lazy();
184+
$nonNullParentResults = $nonNullParentQuery->lazy();
184185

185186
// Combine the results from both queries
186187
$combinedResults = $nullParentResults->concat($nonNullParentResults);

0 commit comments

Comments
 (0)