@@ -82,6 +82,10 @@ class SelectTree extends Field implements HasAffixActions
8282
8383 protected Closure |bool |null $ withTrashed = false ;
8484
85+ protected bool $ storeResults = false ;
86+
87+ protected Collection |array |null $ results = null ;
88+
8589 protected function setUp (): void
8690 {
8791 // Load the state from relationships using a callback function.
@@ -164,6 +168,11 @@ private function buildTree(): Collection
164168 // Combine the results from both queries
165169 $ combinedResults = $ nullParentResults ->concat ($ nonNullParentResults );
166170
171+ // Store results for additional functionality
172+ if ($ this ->storeResults ) {
173+ $ this ->results = $ combinedResults ;
174+ }
175+
167176 return $ this ->buildTreeFromResults ($ combinedResults );
168177 }
169178
@@ -183,7 +192,7 @@ private function buildTreeFromResults($results, $parent = null): Collection
183192 // Group results by their parent IDs
184193 foreach ($ results as $ result ) {
185194 $ parentId = $ result ->{$ this ->getParentAttribute ()};
186- if (! isset ($ resultMap [$ parentId ])) {
195+ if (!isset ($ resultMap [$ parentId ])) {
187196 $ resultMap [$ parentId ] = [];
188197 }
189198 $ resultMap [$ parentId ][] = $ result ;
@@ -374,11 +383,23 @@ public function enableBranchNode(bool $enableBranchNode = true): static
374383 return $ this ;
375384 }
376385
386+ public function storeResults (bool $ storeResults = true ): static
387+ {
388+ $ this ->storeResults = $ storeResults ;
389+
390+ return $ this ;
391+ }
392+
377393 public function getTree (): Collection |array
378394 {
379395 return $ this ->evaluate ($ this ->buildTree ());
380396 }
381397
398+ public function getResults (): Collection |array |null
399+ {
400+ return $ this ->results ;
401+ }
402+
382403 public function getExpandSelected (): bool
383404 {
384405 return $ this ->evaluate ($ this ->expandSelected );
@@ -499,7 +520,7 @@ public function getCreateOptionAction(): ?Action
499520 return null ;
500521 }
501522
502- if (! $ this ->hasCreateOptionActionFormSchema ()) {
523+ if (!$ this ->hasCreateOptionActionFormSchema ()) {
503524 return null ;
504525 }
505526
@@ -510,7 +531,7 @@ public function getCreateOptionAction(): ?Action
510531 ));
511532 })
512533 ->action (static function (Action $ action , array $ arguments , SelectTree $ component , array $ data , ComponentContainer $ form ) {
513- if (! $ component ->getCreateOptionUsing ()) {
534+ if (!$ component ->getCreateOptionUsing ()) {
514535 throw new Exception ("Select field [ {$ component ->getStatePath ()}] must have a [createOptionUsing()] closure set. " );
515536 }
516537
@@ -529,7 +550,7 @@ public function getCreateOptionAction(): ?Action
529550 $ component ->state ($ state );
530551 $ component ->callAfterStateUpdated ();
531552
532- if (! ($ arguments ['another ' ] ?? false )) {
553+ if (!($ arguments ['another ' ] ?? false )) {
533554 return ;
534555 }
535556
0 commit comments