Laravel Form:select() Multi select 选项在数组值为数字时不起作用

Laravel Form:select() Multi select options not working if array value is numeric

形式:select()

我想 select select 中的多个选项,但只有当数组索引键是字符串时它才有效,如果数组索引键是数字它不起作用...

请帮忙..

工作示例:

Form::select($field_data['name'], 
         array('L' => 'Large', 'M' => 'Medium', 'S' => 'Small'), //Options list
         array('S', 'M'), //Selected values
         array('multiple')); //Multiple True
//Result: Form print and Large and Small selected

不能使用数字数组键

Form::select($field_data['name'], 
         array('5' => 'Large', '2' => 'Medium', '10' => 'Small'),  //Options list
         array('10', '2'),  //Selected values
         array('multiple')); //Multiple True

// Just Form>select>options print, but no option selected

我想select多个选项,选项键是数字id..

尝试将其更改为整数。

Form::select($field_data['name'], 
         array(5 => 'Large', 2 => 'Medium', 10 => 'Small'),  //Options list
         array(10, 2),  //Selected values
         array('multiple')); //Multiple True

您可以这样尝试:

$selected = array('10', '2'); //Selected values
Form::select('sections[]',  ['5' => 'Large', '2' => 'Medium', '10' => 'Small'], $selected, ['multiple']);

其实是个bug,已经PR了

https://github.com/LaravelCollective/html/pull/368#pullrequestreview-46820423