我有使用表单过滤信息的问题,过滤的搜索引擎数据
这里是我的代码
$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()之后,但与更多的变量,这将是一个非常低效的解决方案。
如果有人有任何想法提前谢谢。