Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compact(): Undefined variable: operator

Tags:

php

laravel

I'm getting the following error

  (1/1) ErrorException
  compact(): Undefined variable: operator

This is my line of code

$postsCat = Post::whereHas('Cat', function($query) use ($sreachWord) {
    return $query->whereRaw('name REGEXP"'.sql_text_to_regx($sreachWord).'"');
})->orderBy('top','desc')
->orderBy('updated_at','desc')
->paginate(30);

Why is this happening? Is it because of my PHP version (7.3) or something else?

like image 967
Kareimovich Avatar asked Jun 23 '19 17:06

Kareimovich


2 Answers

Go to your project in

vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php

On line number 1337, you can found below code inside the addWhereExistsQuery method

$this->wheres[] = compact('type', 'operator', 'query', 'boolean');

You just remove the 'operator' parameter.

And I hope it will work fine.

like image 51
Hasanur Rahman Himel Avatar answered Nov 06 '22 10:11

Hasanur Rahman Himel


Please refer to this https://github.com/laravel/framework/issues/26936

The version of Laravel would need to be updated.

like image 7
eaststrong Avatar answered Nov 06 '22 12:11

eaststrong