diff --git a/src/SelectTree.php b/src/SelectTree.php index e7f9716..9788bb8 100644 --- a/src/SelectTree.php +++ b/src/SelectTree.php @@ -313,6 +313,8 @@ public function prepend(Closure|array|null $prepend = null): static if (is_array($this->prepend) && isset($this->prepend['name'], $this->prepend['value'])) { $this->prepend['value'] = (string) $this->prepend['value']; + } else if (is_null($this->prepend)){ + # Avoid throwing an exception in case $prepend is explicitly set to null, or a Closure evaluates to null. } else { throw new InvalidArgumentException('The provided prepend value must be an array with "name" and "value" keys.'); } @@ -326,6 +328,8 @@ public function append(Closure|array|null $append = null): static if (is_array($this->append) && isset($this->append['name'], $this->append['value'])) { $this->append['value'] = (string) $this->append['value']; + } else if (is_null($this->append)) { + // Avoid throwing an exception in case $append is explicitly set to null, or a Closure evaluates to null. } else { throw new \InvalidArgumentException('The provided append value must be an array with "name" and "value" keys.'); }