@@ -88,6 +88,8 @@ class SelectTree extends Field implements HasAffixActions
8888
8989 protected Closure |array |null $ prepend = null ;
9090
91+ protected Closure |array |null $ append = null ;
92+
9193 protected Closure |string |null $ treeKey = 'treeKey ' ;
9294
9395 protected function setUp (): void
@@ -316,6 +318,18 @@ public function prepend(Closure|array|null $prepend = null): static
316318 return $ this ;
317319 }
318320
321+ public function append (Closure |array |null $ append = null ): static {
322+ $ this ->append = $ this ->evaluate ($ append );
323+
324+ if (is_array ($ this ->append ) && isset ($ this ->append ['name ' ], $ this ->append ['value ' ])) {
325+ $ this ->append ['value ' ] = (string ) $ this ->append ['value ' ];
326+ } else {
327+ throw new \InvalidArgumentException ('The provided append value must be an array with "name" and "value" keys. ' );
328+ }
329+
330+ return $ this ;
331+ }
332+
319333 public function getRelationship (): BelongsToMany |BelongsTo
320334 {
321335 return $ this ->getModelInstance ()->{$ this ->evaluate ($ this ->relationship )}();
@@ -422,8 +436,10 @@ public function storeResults(bool $storeResults = true): static
422436
423437 public function getTree (): Collection |array
424438 {
425- return $ this ->evaluate ($ this ->buildTree ()->when ($ this ->prepend ,
426- fn (Collection $ tree ) => $ tree ->prepend ($ this ->evaluate ($ this ->prepend ))));
439+ return $ this ->evaluate ($ this ->buildTree ()
440+ ->when ($ this ->prepend , fn (Collection $ tree ) => $ tree ->prepend ($ this ->evaluate ($ this ->prepend )))
441+ ->when ($ this ->append , fn (Collection $ tree ) => $ tree ->push ($ this ->evaluate ($ this ->append )))
442+ );
427443 }
428444
429445 public function getResults (): Collection |array |null
0 commit comments