src/Concerns/Selection.php
public function select(
        string $name,
        iterable $list = [],
        $selected = null,
        array $selectAttributes = [],
        array $optionsAttributes = [],
        array $optgroupsAttributes = []
    ): Htmlable {
        $this->type = 'select';

        // When building a select box the "value" attribute is really the selected one
        // so we will use that when checking the model or session for a value which
        // should provide a convenient method of re-populating the forms on post.
        $selected = $this->getValueAttribute($name, $selected);

        $selectAttributes['id'] = $this->getIdAttribute($name, $selectAttributes);

        if (! isset($selectAttributes['name'])) {
            $selectAttributes['name'] = $name;
        }

        // We will simply loop through the options and build an HTML value for each of
        // them until we have an array of HTML declarations. Then we will join them
        // all together into one single HTML element that can be put on the form.
        $html = [];

        if (isset($selectAttributes['placeholder'])) {
            $html[] = $this->placeholderOption($selectAttributes['placeholder'], $selected);
            unset($selectAttributes['placeholder']);
        }

        if (isset($selectAttributes['native-placeholder'])) {
            $selectAttributes['placeholder'] = $selectAttributes['native-placeholder'];
            unset($selectAttributes['native-placeholder']);
        }

        foreach ($list as $value => $display) {
            $html[] = $this->getSelectOption(
                $display, $value, $selected, $optionsAttributes[$value] ?? [], $optgroupsAttributes[$value] ?? []
            );
        }

        // Once we have all of this HTML, we can join this into a single element after
        // formatting the attributes into an HTML "attributes" string, then we will
        // build out a final select statement, which will contain all the values.
        $options = $this->getHtmlBuilder()->attributes($selectAttributes);

        $list = \implode('', $html);

        return $this->toHtmlString("<select{$options}>{$list}</select>");
    }
public function select(
        string $name,
        iterable $list = [],
        $selected = null,
        array $selectAttributes = [],
        array $optionsAttributes = [],
        array $optgroupsAttributes = []
    ): Htmlable {
        $this->type = 'select';

        // When building a select box the "value" attribute is really the selected one
        // so we will use that when checking the model or session for a value which
        // should provide a convenient method of re-populating the forms on post.
        $selected = $this->getValueAttribute($name, $selected);

        $selectAttributes['id'] = $this->getIdAttribute($name, $selectAttributes);

        if (! isset($selectAttributes['name'])) {
            $selectAttributes['name'] = $name;
        }

        // We will simply loop through the options and build an HTML value for each of
        // them until we have an array of HTML declarations. Then we will join them
        // all together into one single HTML element that can be put on the form.
        $html = [];

        if (isset($selectAttributes['placeholder'])) {
            $html[] = $this->placeholderOption($selectAttributes['placeholder'], $selected);
            unset($selectAttributes['placeholder']);
        }

        if (isset($selectAttributes['native-placeholder'])) {
            $selectAttributes['placeholder'] = $selectAttributes['native-placeholder'];
            unset($selectAttributes['native-placeholder']);
        }

        foreach ($list as $value => $display) {
            $html[] = $this->getSelectOption(
                $display, $value, $selected, $optionsAttributes[$value] ?? [], $optgroupsAttributes[$value] ?? []
            );
        }

        // Once we have all of this HTML, we can join this into a single element after
        // formatting the attributes into an HTML "attributes" string, then we will
        // build out a final select statement, which will contain all the values.
        $options = $this->getHtmlBuilder()->attributes($selectAttributes);

        $list = \implode('', $html);

        return $this->toHtmlString("<select{$options}>{$list}</select>");
    }
Create a select box field.

@param  string $name
@param  iterable  $list
@param  string|array|null  $selected
@param  array  $selectAttributes
@param  array  $optionsAttributes
@param  array  $optgroupsAttributes

@return \Illuminate\Contracts\Support\Htmlable