Skip to content

Commit ad6d66d

Browse files
committed
Create new Method enum options
This will fetch and arrange enum cases to key value pair in datatables. Also, it help to remove custom key value pair inside your Enums.
1 parent eee4dac commit ad6d66d

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|Arrayable $options
128+
* @return $this
129+
*/
130+
public function enumOptions(array|Arrayable $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)