我正在做一个搜索过滤器,我有3个输入“市”,“类别”,“关键字”,我试着插入值数组如果输入不是空的。像这样:Laravel 5.2 - 过滤器阵列
public function search(Request $request)
{
$filter = array(["'visible', '=' , 1"],["'expire_date', '>', $current"]);
if(!empty($termn)){
$filter[] =["'title', 'LIKE' , '%'.$termn.'%'"];
}
if(!empty($request->input('category'))){
$filter[] = ["'category_id', '=', $input_category"];
}
if(!empty($request->input('municipality_id'))) {
$filter[] = ["'municipality_id', '=', $input_municipality"];
}
dd($filter);
$posts = Post::where($filter)->get();
}
也许阵列的结构是不好的,我也尝试这样的: laravel 5.2 search query 但它不工作。 无DD($过滤器)我有此错误:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '.
is null and `'municipality_id', '=', 1` is null)' at line 1 (SQL: select * from `posts` where (`'visible', '=' , 1` is null and `'expire_date', '>', 2016-10-29 13:29:30` is null and `'category_id', '=', Scegli una categoria`.
..
is null and'municipality_id', '=', 1
is null))
谢谢您的帮助!
考虑写更好的问题。那里有这么多。就像“输入”一样,检查是否有空。如果你只是说'$ filter = [..]; $ posts = Post :: where($ filter) - > get();'给出了如此之多的错误。我究竟做错了什么?您将以这种方式获得更多答案。 –