Laravel Scout,使用 where 子句搜索

标签 laravel search where

我刚刚发现了 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/

相关文章:

c 在泛型数组中搜索

python - 如何在 Python 文档中搜索关键字,然后在原始关键字的一定行数内搜索后续关键字?

MySQL : IS NOT NULL check on custom generated column(alias)

oracle - 在where子句中执行Oracle查询

crystal-reports - Crystal 报表中的条件计数()

laravel - 我怎么能在 Laravel 中从另一份工作中分派(dispatch)一份工作

php - Laravel dd 辅助函数返回错误 500

php - Laravel artisan down with message parameter with spaces 给出 Too many arguments, expected arguments "command"

php - 类 stdClass 的对象无法转换为 int Laravel 5.6

search - 如果搜索参数为空或丢失/错误,如何使用 Xpath 函数 'contains()' 不返回任何内容?