working with Laravel 5.6 and I have table name vehicles and in this table data edit form have province, district and town data dependancy selection inputs like this,
<select name="provincename" id="provincename" class="form-control input dynamic" data-dependent="districtname" >
<option value="">{!! $vehicles->provincename !!}</option>
@foreach($town_list as $town)
<option value=""></option>
@endforeach
</select>
<div class="form-group row required">
<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 !!}</option>
</select>
controller for this dependancy
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;
}
but when I click edit form provincename values select correctly in the selection input. but district name not selected acording to vehicle table values. how can I fix this problem? district data coming from towns table
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire