Skip to content

Commit 40cc37f

Browse files
authored
Merge pull request #196 from renitreni/master
feat: new method for enum options
2 parents eee4dac + 8b403bd commit 40cc37f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/Html/Editor/Fields/Field.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,25 @@ public function modelOptions(Builder|string $model, string $value, string $key =
121121
);
122122
}
123123

124+
/**
125+
* Get options from a Enum::cases().
126+
*
127+
* @param array $cases
128+
* @return $this
129+
*/
130+
public function enumOptions(array $cases): static
131+
{
132+
$options = [];
133+
foreach ($cases as $case) {
134+
$options[] = [
135+
'value' => $case->value,
136+
'label' => $case->value,
137+
];
138+
}
139+
140+
return $this->options($options);
141+
}
142+
124143
/**
125144
* Set select options.
126145
*

0 commit comments

Comments
 (0)