Created
July 6, 2013 12:47
-
-
Save ryun/5939787 to your computer and use it in GitHub Desktop.
Form Macro: Multi Select for laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Form::macro('multiselect', function($name, $list = [], array $selected = [], $options = []) | |
{ | |
$options['name'] = $name; | |
$html = array(); | |
if (is_string($selected)) $selected[$selected] = $selected; | |
//dd($list, $selected); | |
foreach ($list as $value => $display) | |
{ | |
$sel = isset($selected[$value])?' selected="selected"':''; | |
$html[] = '<option value="'.$value.'"'.$sel.'>'.e($display).'</option>'; | |
} | |
// build out a final select statement, which will contain all the values. | |
$options = HTML::attributes($options); | |
$list = implode('', $html); | |
return "<select{$options} multiple=\"multiple\">{$list}</select>"; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks :)