Laravel Scout,搜索与clausure

时间:2017-07-24 14:59:32

标签: laravel search where

我刚刚发现了Laravel Scout,我想在哪里进行搜索。代码如下所示

fid = fopen('text.txt', 'r'); % Open up the file
fidw = fopen('text_new.txt', 'w'); % Open up a new file to write

tline = fgetl(fid); % Get the first line in the text file

while ischar(tline) % As long as this line contains characters (i.e. not end of the file)
    % Trim the whitespace
    tline = strtrim(tline);
    % Check if first character is K or k, then write spec at the end of the line
    if tline(1) == 'k' || tline(1) == 'K'
        fprintf(fidw, '%s spec\n', tline);
    % Check if first character is P or p, then write test at the end of the line
    elseif tline(1) == 'p' || tline(1) == 'P'
        fprintf(fidw, '%s test\n', tline);
    % Write the line as is if no conditions match
    else
        fprintf(fidw, '%s\n', tline);
    end

    % Get the next line in the file
    tline = fgetl(fid);
end

% Close the files now
fclose(fid);
fclose(fidw);

但是我收到了这个错误:

类型错误:函数Laravel \ Scout \ Builder :: where()的参数太少,在第36行的/home/vagrant/www/Bee/app/Http/Controllers/SearchController.php中传递了1个,预计正好2个

当我删除where clausure时,没有问题。

1 个答案:

答案 0 :(得分:2)

Scout拥有自己的where()方法,它只接受两个参数:字段和值。所以这样做:

->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的源代码。