【发布时间】:2015-09-29 08:49:57
【问题描述】:
我正在制作我的表单的编辑页面,并且我有一个选择下拉菜单,但我需要为该表单设置选定的值,因为它是一个编辑表单。我是这样做的:
public function edit($id)
{
$form = Form::find($id);
$agent_options = array('' => 'Choose One') + DB::table('agents')->lists('name','id');
$campaign_options = array('' => 'Choose One') + DB::table('campaigns')->lists('name','id');
$query = "SELECT a.id, a.form_id, a.metrics_id, a.response, b.response as responseoption, b.metrics_name, b.description, b.question, a.remarks FROM qcv.forms_responses a INNER JOIN metrics b ON a.metrics_id = b.id WHERE form_id = $id;";
$metric = DB::connection('mysql')->select($query);
return view('form.edit')->with(array('form'=> $form, 'agent_options' => $agent_options, 'campaign_options' => $campaign_options, 'metric' => $metric));
}
在我看来
<div class="col-md-6">
{!! Form::select('agent_id', $agent_options, '',array('class' => 'form-control', 'id' => 'agent_id', 'required' => 'required')) !!}
</div>
让我们使用我的$agent_options 下拉列表,它将在我的代理表中拉出代理列表,但在我看来,如何设置基于代理 ID 选择的默认值?比方说
agend_id = 1
默认选中。
【问题讨论】:
标签: php laravel drop-down-menu query-builder