From 647629afd3fa9ab892d22058a61219cfcb3c60ac Mon Sep 17 00:00:00 2001 From: Krzysztof Grzelak Date: Thu, 20 Jun 2024 19:27:26 +0200 Subject: [PATCH] instance of BackedEnum --- src/Items/BaseItem.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Items/BaseItem.php b/src/Items/BaseItem.php index db1361c..ec11665 100644 --- a/src/Items/BaseItem.php +++ b/src/Items/BaseItem.php @@ -2,6 +2,7 @@ namespace Kgrzelak\LaravelForm\Items; +use BackedEnum; use Illuminate\Contracts\Support\Htmlable; use Stringable; @@ -48,8 +49,12 @@ public function setType(string $type): static return $this; } - public function setValue(?string $value = null): static + public function setValue(mixed $value = null): static { + if ($value instanceof BackedEnum) { + $value = $value->value; + } + $this->value = $value; return $this; @@ -96,9 +101,9 @@ public function toHtml(): string 'options' => $this->options ])->render(); } - + public function __toString(): string { return $this->toHtml(); } -} \ No newline at end of file +}