与Laravel 5.6一起工作,我有表名称工具,并且在此表数据编辑表单中具有省,区和镇数据依赖选择输入,
<select name="provincename" id="provincename" class="form-control input dynamic" data-dependent="districtname" >
<option value="{{$vehicles->provincename}}">{!! $vehicles->provincename !!}</option>
@foreach($town_list as $town)
<option value="{{$town->provincename}}">{{$town->provincename}}</option>
@endforeach
</select>
<div class="form-group row required{{ $errors->has('districtname') ? ' has-error' : '' }}">
<label for="exampleFormControlSelect1" class="col-form-label col-md-3 col-lg-2">District</label>
<div class="col-md-8">
<select name="districtname" id="districtname" class="form-control input dynamic" data-dependent="townname" >
<option value="{{$vehicles->districtname}}">{!! $vehicles->districtname !!}</option>
</select>
这种依赖性的控制器
function fetch(Request $request)
{
$select = $request->get('select');
$value = $request->get('value');
$dependent = $request->get('dependent');
$data = DB::table('towns')
->where($select,$value)
->groupBy($dependent)
->get();
$output = '<option value="">Select '.ucfirst($dependent).'</option>';
foreach ($data as $row) {
$output .= '<option value="' .$row->$dependent. '">
'.$row->$dependent.'</option>';
}
echo $output;
}
但是当我单击编辑表单时,省名值会在选择输入中正确选择。但未根据车辆表格值选择地区名称。我该如何解决这个问题?来自城镇表的地区数据