我在Discuss模型中建立了一个Attribute方法:
/**
* 获取当前讨论的tagList
* @return array
*/
public function getTagListAttribute()
{
return $this->tags->lists('id');
}
控制器中:
public function edit($id)
{
$discuss = Discuss::findOrFail($id);
$tags = Tag::orderBy('sortid')->lists('name','id');
return view('discuss.edit',compact('discuss','tags'));
}
discuss.edit view情况1:下拉菜单无法取到默认tag_list[]值
{!! Form::model($discuss,['method'=>'PATCH','action'=> ['DiscussesCotroller@update',$discuss->id]]) !!}
{!! Form::select('tag_list[]',$tags,null,['class'=>'form-control','multiple']) !!}
{!! Form::close() !!}
discuss.edit view情况2:text可以取到默认tag_list值
{!! Form::model($discuss,['method'=>'PATCH','action'=> ['DiscussesCotroller@update',$discuss->id]]) !!}
{!! Form::text('tag_list',null,['class'=>'form-control']) !!}
{!! Form::close() !!}
discuss.edit view 情况3:`可以直接取tag_list的值`
{ $discuss->tag_list }
请问情况1 无法让select取得默认选中值这种情况怎么办?