【发布时间】:2015-03-19 18:56:09
【问题描述】:
我的项目是关于商店的,属于很多部分。 创建商店时,会在多选列表中选择(选择)部分,并正确保存值。此外,在编辑信息时,用户可以正确保存更改。问题是:在编辑表单中多选对象是明确的(根本没有选择项目),而我们需要根据预先保存的数据设置要选择的选项,以便用户查看和修改它。
在控制器中我选择这样的列表:
public function edit($id)
{
$data = Shops::with('sections')->where('id', '=', $id)->get();
$sectionslst = Sections::lists('section_name','id');
return View::make('admin.shops.edit')->with('data',$data)
->with('sectionslst', $sectionslst );
}
我以这种方式在视图中填充数据
{{Form::label('shop_section','الاقسام') }}
{{ Form::select('shop_sections[]', $sectionslst, array (1, 2), array ('multiple' => 'multiple' ))}}
//I'm using array(1, 2) just to try how it works, but it doesn't, all items still un-selected :-(
【问题讨论】:
-
你能给我们看看
$sectionlst的转储吗? -
我编辑了我的问题。请再检查一遍。 @lukasgeiter
-
谢谢,但我不是这个意思。制作
var_dump($sectionlst),然后请在此处复制粘贴输出而不是屏幕截图。另外你使用的是什么版本的 Laravel? -
我使用的是最新版本 4.2。结果是:
-
编辑你的问题会更好,但我想我看到了问题......你甚至没有 ID
1,2!改用array(13,14)
标签: php html dom laravel laravel-4