Skip to content

Instantly share code, notes, and snippets.

@ryun
Created July 6, 2013 12:47
Show Gist options
  • Save ryun/5939787 to your computer and use it in GitHub Desktop.
Save ryun/5939787 to your computer and use it in GitHub Desktop.
Form Macro: Multi Select for laravel
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>";
});
Copy link

ghost commented Sep 6, 2014

Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment