【发布时间】:2015-07-05 16:51:29
【问题描述】:
我正在学习 Laravel,在尝试将模型的属性绑定到选择标记的选定值时遇到问题。我试图将第三个参数保留为 null,因为我相信 Form Model Binding 会自动处理它,但它不起作用。这是我已经尝试过的:
{{$article->tag_list}} // show [1,3]
//it doesn't work
{!! Form::select('tag_list[]', $tags, null , ['class' => 'form-control', 'multiple'] ) !!}
-------------
//it doesn't work as well
{!! Form::select('tag_list[]', $tags, $article->tag_list , ['class' => 'form-control', 'multiple'] ) !!}
-----------
//it works
{!! Form::select('tag_list[]', $tags, [1,3] , ['class' => 'form-control', 'multiple'] ) !!}
在模型中,我有 getTagListAttribute() 工作正常。
public function getTagListAttribute(){
return $this->tags->lists('id');
}
使用文本输入,表单可以正常工作。顺便说一句,我使用的是 5.2.1 版本。我在这里错过了什么?
【问题讨论】: