@@ -126,32 +126,35 @@ private function buildTreeFromResults($results, $parent = null): Collection
126126 $ resultMap [$ parentId ][] = $ result ;
127127 }
128128
129+ // Define disabled options
130+ $ disabledOptions = $ this ->getDisabledOptions ();
131+
129132 // Recursively build the tree starting from the root (null parent)
130133 $ rootResults = $ resultMap [$ parent ] ?? [];
131134 foreach ($ rootResults as $ result ) {
132135 // Build a node and add it to the tree
133- $ node = $ this ->buildNode ($ result , $ resultMap );
136+ $ node = $ this ->buildNode ($ result , $ resultMap, $ disabledOptions );
134137 $ tree ->push ($ node );
135138 }
136139
137140 return $ tree ;
138141 }
139142
140- private function buildNode ($ result , $ resultMap ): array
143+ private function buildNode ($ result , $ resultMap, $ disabledOptions ): array
141144 {
142145 // Create a node with 'name' and 'value' attributes
143146 $ node = [
144147 'name ' => $ result ->{$ this ->getTitleAttribute ()},
145148 'value ' => $ result ->getKey (),
146- 'disabled ' => in_array ($ result ->getKey (), $ this -> getDisabledOptions () ),
149+ 'disabled ' => in_array ($ result ->getKey (), $ disabledOptions ),
147150 ];
148151
149152 // Check if the result has children
150153 if (isset ($ resultMap [$ result ->getKey ()])) {
151154 $ children = collect ();
152155 // Recursively build child nodes
153156 foreach ($ resultMap [$ result ->getKey ()] as $ child ) {
154- $ childNode = $ this ->buildNode ($ child , $ resultMap );
157+ $ childNode = $ this ->buildNode ($ child , $ resultMap, $ disabledOptions );
155158 $ children ->push ($ childNode );
156159 }
157160 // Add children to the node
0 commit comments