【发布时间】:2018-08-17 18:15:15
【问题描述】:
我有两个表作为用户和部门。我的部门表有两列作为 id 和标题,我的用户表包含用户信息列和一个 exta 列作为与部门表 id 相关的 dept_id。
I want to create a dropdown select option for departement and when a departement is selected the users which have that related department id should be displayed into another dropdown, how can i do that..?
我正在获取控制器中的所有用户和部门数据并将其发送到查看。
我的控制器是....
public function index()
{
$user = DB::table('users')->get();
$dept = DB::table('departments')->get();
return view('userview', compact('user', 'dept'));
}
我的看法是……
<select class="form-control" id="department" name="department" >
@foreach($dept as $dept)
<option value="{{ $dept->id }}">{{ $dept->name }}</option>
@endforeach
</select>
<select class="form-control" id="user" name="user" >
<option> </option>
</select>
【问题讨论】: