Php 在laravel的多选下拉列表中预选值

Php 在laravel的多选下拉列表中预选值,php,laravel-4,Php,Laravel 4,我对Laravel和使用Laravel4相对较新,但长期以来一直使用PHP和C。看起来这应该很容易,但我找不到任何地方可以告诉我怎么做 在我的控制器中,我从数据库获取数据并将其发送到视图,如下所示: $sections = DB::table('paperSections')->lists('section','id'); return View::make('layouts.publisher.step2', array('sections' => $sections)); &l

我对Laravel和使用Laravel4相对较新,但长期以来一直使用PHP和C。看起来这应该很容易,但我找不到任何地方可以告诉我怎么做

在我的控制器中,我从数据库获取数据并将其发送到视图,如下所示:

$sections = DB::table('paperSections')->lists('section','id');
return View::make('layouts.publisher.step2', array('sections' => $sections));
<select multiple="multiple" id="sections" name="sections">
<option value="1">News</option>
<option value="2">Sports</option>
<option value="3">Features</option>
<option value="4">Arts and Entertainment</option>
<option value="5">Technology and Science</option>
<option value="6">Op-Ed</option>
</select>
在我看来,我有以下几点:

{{ Form::select('sections[]', $sections, '', array('multiple')) }}
这将生成如下所示的选择列表:

$sections = DB::table('paperSections')->lists('section','id');
return View::make('layouts.publisher.step2', array('sections' => $sections));
<select multiple="multiple" id="sections" name="sections">
<option value="1">News</option>
<option value="2">Sports</option>
<option value="3">Features</option>
<option value="4">Arts and Entertainment</option>
<option value="5">Technology and Science</option>
<option value="6">Op-Ed</option>
</select>

假设我有一个字符串,例如1,3,5,它表示前面选择的多个选项。如何使用该字符串重新选择这三个选项?

将所选选项的数组作为第三个参数传递:

$selected = explode(',', $idsAsString);

Form::select('sections[]', $sections, $selected, ['multiple'])

将选定选项的数组作为第三个参数传递:

$selected = explode(',', $idsAsString);

Form::select('sections[]', $sections, $selected, ['multiple'])

将选定选项的数组作为第三个参数传递:

$selected = explode(',', $idsAsString);

Form::select('sections[]', $sections, $selected, ['multiple'])

将选定选项的数组作为第三个参数传递:

$selected = explode(',', $idsAsString);

Form::select('sections[]', $sections, $selected, ['multiple'])

谢谢很好用,谢谢。很好用,谢谢。很好用,谢谢。工作完美。