From ec9f5f1995209ff9f1f19968c4f642f5cfed532a Mon Sep 17 00:00:00 2001 From: crynobone Date: Mon, 7 May 2012 20:43:40 +0800 Subject: [PATCH] Add support for Form::select with optgroup, solved #526 --- laravel/form.php | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/laravel/form.php b/laravel/form.php index a768f503..619043ef 100644 --- a/laravel/form.php +++ b/laravel/form.php @@ -397,12 +397,39 @@ public static function select($name, $options = array(), $selected = null, $attr foreach ($options as $value => $display) { - $html[] = static::option($value, $display, $selected); + if (is_array($display)) + { + $html[] = static::optgroup($display, $value, $selected); + } + else + { + $html[] = static::option($value, $display, $selected); + } } return ''.implode('', $html).''; } + /** + * Create a HTML select element optgroup. + * + * @param array $options + * @param string $label + * @param string $selected + * @return string + */ + protected static function optgroup($options, $label, $selected) + { + $html = array(); + + foreach ($options as $value => $display) + { + $html[] = static::option($value, $display, $selected); + } + + return ''.implode('', $html).''; + } + /** * Create a HTML select element option. *