Skip to content

Commit 1a209d0

Browse files
authored
Update Select.php
1 parent 721f40f commit 1a209d0

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Fields/Select.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
use Closure;
99
use Cone\Root\Filters\Filter;
1010
use Cone\Root\Filters\RenderableFilter;
11+
use function Illuminate\Support\enum_value;
1112
use Illuminate\Database\Eloquent\Builder;
1213
use Illuminate\Database\Eloquent\Model;
1314
use Illuminate\Http\Request;
1415
use Illuminate\Support\Arr;
16+
1517
use Illuminate\Support\Collection;
1618

1719
class Select extends Field
@@ -78,7 +80,7 @@ public function resolveFormat(Request $request, Model $model): ?string
7880

7981
return Collection::make($value)
8082
->map(static function (mixed $value) use ($options): string {
81-
$value = $value instanceof BackedEnum ? $value->value : $value;
83+
$value = enum_value($value);
8284

8385
return $options[$value] ?? $value;
8486
})
@@ -115,7 +117,10 @@ public function resolveOptions(Request $request, Model $model): array
115117
return array_map(function (mixed $label, mixed $option) use ($value): array {
116118
$option = $label instanceof Option ? $label : $this->newOption($option, $label);
117119

118-
$option->selected(in_array($option->getAttribute('value'), $value));
120+
$option->selected(in_array(
121+
$option->getAttribute('value'),
122+
array_map(fn (mixed $v): mixed => enum_value($v), $value)
123+
));
119124

120125
return $option->toArray();
121126
}, $options, array_keys($options));

0 commit comments

Comments
 (0)