Search code examples
phpformslaravellaravelcollective

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


Form:select()

I want to select multiple options in select, but its only work if Array index key is string, If array index key is numeric its not working...

Any help please..

Working Example:

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

Not working with Numeric Array Keys

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

I want to select multiple option, and options keys are numeric ids..


Solution

  • Try changing it to integers.

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