2017-07-31 63 views
0

表:選擇()Laravel形式:選擇()多選選項不工作,如果數組值是數字

我想選擇在選擇多個選項,但其唯一的工作,如果數組索引鍵是字符串,如果數組索引鍵是數字它不工作...

任何幫助,請..

工作實例:

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 

我想選擇多個選項,選項鍵數字ID工作..

回答

1

嘗試將其更改爲整數。

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

謝謝...其實我是這樣做動態的,所以我總是接受字符串值,現在我會改變我的代碼,以使其更加靈活:) –

+0

@AsadRaza,歡迎。是的,如果可能的話,這是很好的做法。 :) –

0

你可以嘗試這樣的:

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