@@ -88,6 +88,8 @@ class SelectTree extends Field implements HasAffixActions
88
88
89
89
protected Closure |array |null $ prepend = null ;
90
90
91
+ protected Closure |array |null $ append = null ;
92
+
91
93
protected Closure |string |null $ treeKey = 'treeKey ' ;
92
94
93
95
protected function setUp (): void
@@ -316,6 +318,19 @@ public function prepend(Closure|array|null $prepend = null): static
316
318
return $ this ;
317
319
}
318
320
321
+ public function append (Closure |array |null $ append = null ): static
322
+ {
323
+ $ this ->append = $ this ->evaluate ($ append );
324
+
325
+ if (is_array ($ this ->append ) && isset ($ this ->append ['name ' ], $ this ->append ['value ' ])) {
326
+ $ this ->append ['value ' ] = (string ) $ this ->append ['value ' ];
327
+ } else {
328
+ throw new \InvalidArgumentException ('The provided append value must be an array with "name" and "value" keys. ' );
329
+ }
330
+
331
+ return $ this ;
332
+ }
333
+
319
334
public function getRelationship (): BelongsToMany |BelongsTo
320
335
{
321
336
return $ this ->getModelInstance ()->{$ this ->evaluate ($ this ->relationship )}();
@@ -422,8 +437,10 @@ public function storeResults(bool $storeResults = true): static
422
437
423
438
public function getTree (): Collection |array
424
439
{
425
- return $ this ->evaluate ($ this ->buildTree ()->when ($ this ->prepend ,
426
- fn (Collection $ tree ) => $ tree ->prepend ($ this ->evaluate ($ this ->prepend ))));
440
+ return $ this ->evaluate ($ this ->buildTree ()
441
+ ->when ($ this ->prepend , fn (Collection $ tree ) => $ tree ->prepend ($ this ->evaluate ($ this ->prepend )))
442
+ ->when ($ this ->append , fn (Collection $ tree ) => $ tree ->push ($ this ->evaluate ($ this ->append )))
443
+ );
427
444
}
428
445
429
446
public function getResults (): Collection |array |null
0 commit comments