Skip to content

Commit 8fe1e69

Browse files
committed
feat: create options from array
1 parent 1f495cf commit 8fe1e69

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/Html/Editor/Fields/Options.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@ public static function yesNo(): static
2828
return new static($data);
2929
}
3030

31+
/**
32+
* Create options from an array.
33+
*
34+
* @param array<array-key, string|int|float|array{label: string, value: mixed}> $data
35+
*/
36+
public static function from(array $data): static
37+
{
38+
$items = [];
39+
foreach ($data as $key => $value) {
40+
$items[] = is_array($value) ? $value : ['label' => $value, 'value' => $key];
41+
}
42+
43+
return new static($items);
44+
}
45+
3146
/**
3247
* Get options from a model.
3348
*

0 commit comments

Comments
 (0)