我有一个小问题,即使没有搜索键也会显示搜索结果。这是片段。这是观点:
<form action="/search" method="GET">
<div class="form-group search-location">
<input type="text" name="cityKey" id="cityKey" value="{{ request()->input('cityKey') }}"
class="form-control" >
</div>
<div class="form-group search-info">
<input type="text" name="key" id="key" value="{{ request()->input('key') }}"
class="form-control" >
</div>
<button type="submit" class="btn btn-primary search-btn"><i class="fas fa-search"></i>
<span>search</span></button>
这是控制器:
public function search(Request $request){
$cityKey = $request->cityKey;
$key = $request->key;
$doctors = Doctor_list::where('speciality_title', 'LIKE', '%' . $key . '%')->
where('location', 'LIKE', '%' . $cityKey . '%')->
orWhere('doctors_name', 'LIKE', '%' . $key . '%')->
where('location', 'LIKE', '%' . $cityKey . '%')->
orWhere('speciality_type', 'LIKE', '%' . $key . '%')->
where('location', 'LIKE', '%' . $cityKey . '%');
//完成查询并使用分页或 ->get() 终止查询 $doctors = $doctors->get();
return view('search', compact('doctors'));
}
繁花如伊