How can I use the change event of a Form::select
to fill in another Form::select
?
Example:
I charge a main Select with some departments:
Controller
$masterareas = dk_master_area::orderBy('name','asc')->get();
$data = array();
foreach ($masterareas as $masterarea) {
$areas = dk_area::where('id_master_area','=',$masterarea->id)->orderBy('name','asc')->get();
$tdata = array();
foreach ($areas as $area) {
$tdata[$area->id] = $area->name;
}
$data[$masterarea->name] = $tdata;
}
return view('user/create', ['areas'=>$data]);
View:
{!!Form::select('areas',$areas,null,['id'=>'areas','class'=>'form-control'])!!}
This is the result:
Depending on the area you choose, I must find the department in that area to charge the charges available to the Department, which at the base level are already related, so I can know what charge belongs to that department.
But I do not know how I can do, so when choosing an area, I can load in a second select, the charges. Should I use the same Form::select
or simply a normal select? I do not want to have problems when trying to save the data.