@@ -82,6 +82,10 @@ class SelectTree extends Field implements HasAffixActions
82
82
83
83
protected Closure |bool |null $ withTrashed = false ;
84
84
85
+ protected bool $ storeResults = false ;
86
+
87
+ protected Collection |array |null $ results = null ;
88
+
85
89
protected function setUp (): void
86
90
{
87
91
// Load the state from relationships using a callback function.
@@ -164,6 +168,11 @@ private function buildTree(): Collection
164
168
// Combine the results from both queries
165
169
$ combinedResults = $ nullParentResults ->concat ($ nonNullParentResults );
166
170
171
+ // Store results for additional functionality
172
+ if ($ this ->storeResults ) {
173
+ $ this ->results = $ combinedResults ;
174
+ }
175
+
167
176
return $ this ->buildTreeFromResults ($ combinedResults );
168
177
}
169
178
@@ -183,7 +192,7 @@ private function buildTreeFromResults($results, $parent = null): Collection
183
192
// Group results by their parent IDs
184
193
foreach ($ results as $ result ) {
185
194
$ parentId = $ result ->{$ this ->getParentAttribute ()};
186
- if (! isset ($ resultMap [$ parentId ])) {
195
+ if (!isset ($ resultMap [$ parentId ])) {
187
196
$ resultMap [$ parentId ] = [];
188
197
}
189
198
$ resultMap [$ parentId ][] = $ result ;
@@ -374,11 +383,23 @@ public function enableBranchNode(bool $enableBranchNode = true): static
374
383
return $ this ;
375
384
}
376
385
386
+ public function storeResults (bool $ storeResults = true ): static
387
+ {
388
+ $ this ->storeResults = $ storeResults ;
389
+
390
+ return $ this ;
391
+ }
392
+
377
393
public function getTree (): Collection |array
378
394
{
379
395
return $ this ->evaluate ($ this ->buildTree ());
380
396
}
381
397
398
+ public function getResults (): Collection |array |null
399
+ {
400
+ return $ this ->results ;
401
+ }
402
+
382
403
public function getExpandSelected (): bool
383
404
{
384
405
return $ this ->evaluate ($ this ->expandSelected );
@@ -499,7 +520,7 @@ public function getCreateOptionAction(): ?Action
499
520
return null ;
500
521
}
501
522
502
- if (! $ this ->hasCreateOptionActionFormSchema ()) {
523
+ if (!$ this ->hasCreateOptionActionFormSchema ()) {
503
524
return null ;
504
525
}
505
526
@@ -510,7 +531,7 @@ public function getCreateOptionAction(): ?Action
510
531
));
511
532
})
512
533
->action (static function (Action $ action , array $ arguments , SelectTree $ component , array $ data , ComponentContainer $ form ) {
513
- if (! $ component ->getCreateOptionUsing ()) {
534
+ if (!$ component ->getCreateOptionUsing ()) {
514
535
throw new Exception ("Select field [ {$ component ->getStatePath ()}] must have a [createOptionUsing()] closure set. " );
515
536
}
516
537
@@ -529,7 +550,7 @@ public function getCreateOptionAction(): ?Action
529
550
$ component ->state ($ state );
530
551
$ component ->callAfterStateUpdated ();
531
552
532
- if (! ($ arguments ['another ' ] ?? false )) {
553
+ if (!($ arguments ['another ' ] ?? false )) {
533
554
return ;
534
555
}
535
556
0 commit comments