| @@ 57-69 (lines=13) @@ | ||
| 54 | * |
|
| 55 | * @return static |
|
| 56 | */ |
|
| 57 | public function options($options) |
|
| 58 | { |
|
| 59 | return $this->addChildren($options, function ($text, $value) { |
|
| 60 | if (is_array($text)) { |
|
| 61 | return $this->optgroup($value, $text); |
|
| 62 | } |
|
| 63 | ||
| 64 | return Option::create() |
|
| 65 | ->value($value) |
|
| 66 | ->text($text) |
|
| 67 | ->selectedIf($value === $this->value); |
|
| 68 | }); |
|
| 69 | } |
|
| 70 | ||
| 71 | /** |
|
| 72 | * @param string $label |
|
| @@ 77-89 (lines=13) @@ | ||
| 74 | * |
|
| 75 | * @return static |
|
| 76 | */ |
|
| 77 | public function optgroup($label, $options) |
|
| 78 | { |
|
| 79 | return Optgroup::create() |
|
| 80 | ->label($label) |
|
| 81 | ->addChildren($options, function ($text, $value) { |
|
| 82 | return Option::create() |
|
| 83 | ->value($value) |
|
| 84 | ->text($text) |
|
| 85 | ->selectedIf($value === $this->value); |
|
| 86 | }); |
|
| 87 | ||
| 88 | return $this->addChild($optgroup); |
|
| 89 | } |
|
| 90 | ||
| 91 | /** |
|
| 92 | * @param string|null $text |
|