|
8 | 8 | use Closure; |
9 | 9 | use Cone\Root\Filters\Filter; |
10 | 10 | use Cone\Root\Filters\RenderableFilter; |
| 11 | +use function Illuminate\Support\enum_value; |
11 | 12 | use Illuminate\Database\Eloquent\Builder; |
12 | 13 | use Illuminate\Database\Eloquent\Model; |
13 | 14 | use Illuminate\Http\Request; |
14 | 15 | use Illuminate\Support\Arr; |
| 16 | + |
15 | 17 | use Illuminate\Support\Collection; |
16 | 18 |
|
17 | 19 | class Select extends Field |
@@ -78,7 +80,7 @@ public function resolveFormat(Request $request, Model $model): ?string |
78 | 80 |
|
79 | 81 | return Collection::make($value) |
80 | 82 | ->map(static function (mixed $value) use ($options): string { |
81 | | - $value = $value instanceof BackedEnum ? $value->value : $value; |
| 83 | + $value = enum_value($value); |
82 | 84 |
|
83 | 85 | return $options[$value] ?? $value; |
84 | 86 | }) |
@@ -115,7 +117,10 @@ public function resolveOptions(Request $request, Model $model): array |
115 | 117 | return array_map(function (mixed $label, mixed $option) use ($value): array { |
116 | 118 | $option = $label instanceof Option ? $label : $this->newOption($option, $label); |
117 | 119 |
|
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 | + )); |
119 | 124 |
|
120 | 125 | return $option->toArray(); |
121 | 126 | }, $options, array_keys($options)); |
|
0 commit comments