Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Scout, search with where clausure

I just discovered Laravel Scout and I wanted to make a search with where clausure. The code shown below

$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);

But I'm getting this error:

Type error: Too few arguments to function Laravel\Scout\Builder::where(), 1 passed in /home/vagrant/www/Bee/app/Http/Controllers/SearchController.php on line 36 and exactly 2 expected

When I remove where clausure, there is no problem.

like image 629
Yavuz Koca Avatar asked Jan 28 '26 01:01

Yavuz Koca


1 Answers

Scout has it's own where() method which accepts just two parameters: field and value. So do this:

->where('course_id', $course_id)
->where('course_code_number', $request->course_code_number_search)

Instead of this:

->where([
    ['course_id','=',$course_id],
    ['course_code_number', '=', $request->course_code_number_search]
])

You can look at the source code of the where() method here.

   

like image 193
Alexey Mezenin Avatar answered Jan 30 '26 21:01

Alexey Mezenin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!