我刚刚发现了 Laravel Scout,我想用 where 子句进行搜索。代码如下所示
$notes = Note::search($request->lecturer_search)->where([
['course_id','=',$course_id],
['course_code_number', '=', $request->course_code_number_search]
])->orderBy('created_at','desc')->paginate(5);
但是我收到了这个错误:
类型错误:函数 Laravel\Scout\Builder::where() 的参数太少,在第 36 行传入/home/vagrant/www/Bee/app/Http/Controllers/SearchController.php 中有 1 个,预期只有 2 个
当我删除 where 子句时,没有问题。
最佳答案
Scout 有它自己的 where()
方法,它只接受两个参数:field 和 value。所以这样做:
->where('course_id', $course_id)
->where('course_code_number', $request->course_code_number_search)
取而代之的是:
->where([
['course_id','=',$course_id],
['course_code_number', '=', $request->course_code_number_search]
])
可以看where()
方法的源码here .
关于Laravel Scout,使用 where 子句搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45283879/