laravel7 下拉搜索
html:页面
首先给下拉框一个页面改变事件,将下拉框的值发送至后台,进行查询
<select name="interest" id="serarch" onchange="serch()" class="input-text" > <option value="1">妇产科</option> <option value="2">儿科</option> <option value="3">耳鼻喉科</option> </select>
引入jq
function serch() { // 获取下拉框的分类值,这里的数字 var value=$('#serarch').val(); //发送值 location.href='/department?value='+value; }
定义路由:
Route::get('seracher','DepartmentController@seracher');
控制器接受值
public function department(Request $request) { $value=$request->get('value'); // 下拉搜索 $data = DB::table('doctors') ->join('departments', 'doctors.departments_id', '=', 'departments.id') ->where('departments.id','=',"$value") ->paginate(6); return view('department.index',compact('data')); }
效果图