@@ -113,7 +113,7 @@ protected function setUp(): void
113113
114114 $ form ->model ($ record )->saveRelationships ();
115115
116- return $ record ->{ $ this ->getCustomKey ()} ;
116+ return $ this ->getCustomKey ($ record ) ;
117117 });
118118
119119 $ this ->suffixActions ([
@@ -183,8 +183,8 @@ private function buildTreeFromResults($results, $parent = null): Collection
183183
184184 private function buildNode ($ result , $ resultMap , $ disabledOptions , $ hiddenOptions ): array
185185 {
186- $ key = $ result ->{ $ this ->getCustomKey ()} ;
187-
186+ $ key = $ this ->getCustomKey ($ result ) ;
187+
188188 // Create a node with 'name' and 'value' attributes
189189 $ node = [
190190 'name ' => $ result ->{$ this ->getTitleAttribute ()},
@@ -200,7 +200,7 @@ private function buildNode($result, $resultMap, $disabledOptions, $hiddenOptions
200200 // Recursively build child nodes
201201 foreach ($ resultMap [$ key ] as $ child ) {
202202 // don't add the hidden ones
203- if (in_array ($ child ->{ $ this ->getCustomKey ()} , $ hiddenOptions )) {
203+ if (in_array ($ this ->getCustomKey ($ child ) , $ hiddenOptions )) {
204204 continue ;
205205 }
206206 $ childNode = $ this ->buildNode ($ child , $ resultMap , $ disabledOptions , $ hiddenOptions );
@@ -306,7 +306,7 @@ public function independent(bool $independent = true): static
306306 return $ this ;
307307 }
308308
309- public function withKey (string $ customKey = ' id ' ): static
309+ public function withKey (string $ customKey ): static
310310 {
311311 $ this ->customKey = $ customKey ;
312312
@@ -360,10 +360,10 @@ public function getIndependent(): bool
360360 {
361361 return $ this ->evaluate ($ this ->independent );
362362 }
363-
364- public function getCustomKey (): string
363+
364+ public function getCustomKey ($ record )
365365 {
366- return is_null ($ this ->customKey ) ? $ this ->getKey () : $ this -> evaluate ( $ this ->customKey ) ;
366+ return is_null ($ this ->customKey ) ? $ record ->getKey () : $ record ->{ $ this ->customKey } ;
367367 }
368368
369369 public function getWithCount (): bool
0 commit comments