Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/SelectTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,13 @@ public function multiple(Closure|bool $multiple = true): static

public function prepend(Closure|array|null $prepend = null): static
{
$this->prepend = $prepend;
$this->prepend = $this->evaluate($prepend);

if (is_array($this->prepend) && isset($this->prepend['name'], $this->prepend['value'])) {
$this->prepend['value'] = (string) $this->prepend['value'];
} else {
throw new \InvalidArgumentException('The provided prepend value must be an array with "name" and "value" keys.');
}

return $this;
}
Expand Down Expand Up @@ -441,9 +447,11 @@ public function getIndependent(): bool
return $this->evaluate($this->independent);
}

public function getCustomKey($record)
public function getCustomKey($record): string
{
return is_null($this->customKey) ? $record->getKey() : $record->{$this->customKey};
$key = is_null($this->customKey) ? $record->getKey() : $record->{$this->customKey};

return (string) $key;
}

public function getWithCount(): bool
Expand Down Expand Up @@ -614,4 +622,15 @@ public function createOptionModalHeading(string|Closure|null $heading): static

return $this;
}

public function getState(): mixed
{
$state = parent::getState();

if (is_array($state)) {
return array_map(fn ($value) => (string) $value, $state);
}

return (string) $state;
}
}