我有使用表單過濾信息的問題,過濾的搜索引擎數據
這裏是我的代碼
$cooperation = Cooperation::with('user')->get();
$search_results = [];
$search = Input::get('q');
$category = Input::get('c');
$land = Input::get('l');
if(!empty($search || $category || $land)){
$search_results = $cooperation;
if (!empty($search)){
$search_results = $search_results->where('title', 'like', '%'. $search .'%');
}
if (!empty($category)){
$search_results = $search_results->where('category', $category);
}
if (!empty($land)){
$search_results = $search_results->where('land', $land);
}
$exist_s = true;
$not_s = false;
return view('cooperation.index', compact('cooperation', 'search_results', 'exist_s', 'not_s'));
}
else{
$not_s = true;
$exist_s = false;
return view('cooperation.index', compact('cooperation', 'search_results', 'exist_s', 'not_s'));
}
從我試圖通過按順序排列,以篩選形式檢索數據後每個變量但沒有任何反應,唯一可行的是在$ category中過濾,但我不知道爲什麼其餘的不起作用。我正在尋找一個解決方案,以便如何有效地過濾數據,我可以做if()if()之後,但與更多的變量,這將是一個非常低效的解決方案。
如果有人有任何想法提前謝謝。