/** * Import options from array * * @param array $options * @return SelectOptionGroup */ public function importOptions(array $options = []) { foreach ($options as $option) { $value = isset($option['value']) ? $option['value'] : null; $title = isset($option['title']) ? $option['title'] : $option['value']; $selected = isset($option['selected']) ? true : false; $this->addOption(SelectOption::forge()->setOptionParams($value, $title, $selected)); } return $this; }
/** * Import options from array * * @param array $options * * @return Select */ public function importOptions(array $options = []) { foreach ($options as $option) { if (isset($option['options']) && is_array($option['options'])) { $label = isset($option['label']) ? $option['label'] : null; $groupOptions = !empty($option['options']) ? $option['options'] : []; $this->addGroup(SelectOptionGroup::forge()->setTitle($label)->importOptions($groupOptions)); } else { $value = isset($option['value']) ? $option['value'] : null; $title = isset($option['title']) ? $option['title'] : $option['value']; $selected = isset($option['selected']) ? true : false; $this->addOption(SelectOption::forge()->setOptionParams($value, $title, $selected)); } } return $this; }