src/Concerns/Selection.php
protected function optionGroup(
        iterable $list,
        string $label,
        $selected,
        array $attributes = [],
        array $optionsAttributes = [],
        int $level = 0
    ): Htmlable {
        $html  = [];
        $space = \str_repeat('&nbsp;', $level);

        foreach ($list as $value => $display) {
            if (\is_iterable($display)) {
                $html[] = $this->option(
                    $display, $value, $selected, $optionsAttributes[$value] ?? [], $level + 5
                );
            } else {
                $html[] = $this->option(
                    $space.$display, $value, $selected, $optionsAttributes[$value] ?? []
                );
            }
        }

        return $this->toHtmlString(\sprintf(
            '<optgroup label="%s"%s>%s</optgroup>',
            $this->entities($label),
            $this->getHtmlBuilder()->attributes($attributes),
            \implode('', $html)
        ));
    }
protected function optionGroup(
        iterable $list,
        string $label,
        $selected,
        array $attributes = [],
        array $optionsAttributes = [],
        int $level = 0
    ): Htmlable {
        $html  = [];
        $space = \str_repeat('&nbsp;', $level);

        foreach ($list as $value => $display) {
            if (\is_iterable($display)) {
                $html[] = $this->option(
                    $display, $value, $selected, $optionsAttributes[$value] ?? [], $level + 5
                );
            } else {
                $html[] = $this->option(
                    $space.$display, $value, $selected, $optionsAttributes[$value] ?? []
                );
            }
        }

        return $this->toHtmlString(\sprintf(
            '<optgroup label="%s"%s>%s</optgroup>',
            $this->entities($label),
            $this->getHtmlBuilder()->attributes($attributes),
            \implode('', $html)
        ));
    }
Create an option group form element.

@param  iterable   $list
@param  string  $label
@param  string|array|null  $selected
@param  array  $attributes
@param  array  $optionsAttributes
@param  int  $level

@return \Illuminate\Contracts\Support\Htmlable