@@ -84,6 +84,11 @@ class SelectTree extends Field implements HasAffixActions
8484
8585 protected Collection |array |null $ results = null ;
8686
87+ protected Closure |bool |null $ multiple = null ;
88+
89+ protected Closure |array |null $ prepend = null ;
90+
91+
8792 protected function setUp (): void
8893 {
8994 // Load the state from relationships using a callback function.
@@ -143,7 +148,7 @@ protected function setUp(): void
143148 ]);
144149 }
145150
146- private function buildTree (): Collection
151+ protected function buildTree (): Collection
147152 {
148153 // Start with two separate query builders
149154 $ nullParentQuery = $ this ->getRelationship ()->getRelated ()->query ()->where ($ this ->getParentAttribute (), $ this ->getParentNullValue ());
@@ -288,6 +293,19 @@ public function parentNullValue(int|string|null $parentNullValue = null): static
288293 return $ this ;
289294 }
290295
296+ public function multiple (Closure |bool $ multiple = true ): static
297+ {
298+ $ this ->multiple =$ this ->evaluate ($ multiple );
299+ return $ this ;
300+ }
301+
302+ public function prepend (Closure |array |null $ prepend = null ): static
303+ {
304+ $ this ->prepend = $ this ->evaluate ($ prepend );
305+ return $ this ;
306+ }
307+
308+
291309 public function getRelationship (): BelongsToMany |BelongsTo
292310 {
293311 return $ this ->getModelInstance ()->{$ this ->evaluate ($ this ->relationship )}();
@@ -394,7 +412,7 @@ public function storeResults(bool $storeResults = true): static
394412
395413 public function getTree (): Collection |array
396414 {
397- return $ this ->evaluate ($ this ->buildTree ());
415+ return $ this ->evaluate ($ this ->buildTree ()-> when ( $ this -> prepend , fn ( Collection $ tree ) => $ tree -> prepend ( $ this -> prepend )) );
398416 }
399417
400418 public function getResults (): Collection |array |null
@@ -434,7 +452,9 @@ public function getWithCount(): bool
434452
435453 public function getMultiple (): bool
436454 {
437- return $ this ->evaluate ($ this ->getRelationship () instanceof BelongsToMany);
455+ return $ this ->evaluate (
456+ is_null ($ this ->multiple ) ? $ this ->getRelationship () instanceof BelongsToMany : $ this ->multiple
457+ );
438458 }
439459
440460 public function getClearable (): bool
0 commit comments