Framework: [5.5] WhereHas method blows up on PHP 7.3 when explicitly specifying an operator

Created on 13 Aug 2018  路  8Comments  路  Source: laravel/framework

  • Laravel Version: 5.5.42
  • PHP Version: 7.3.0beta1
  • Database Driver & Version: SQLite 3.24.0-1

Description:

Running a whereHas method off a hasMany relation blows up with:
ErrorException: compact(): Undefined variable: operator in file /var/www/testproject/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php on line 1243

Steps To Reproduce:

  1. Define a hasMany relation on a model. Ensure that the child model on the relation has at least one relation other than to the parent.
  2. Query the parent's hasMany relation - here's how I tripped over it:
$result = $parentModel->manyRelation()->whereHas('childOtherRelation', function ($query) use ($value) {
    $query->where('name', '=', $value);
})->firstOrFail();
  1. Execute that query under PHP 7.3. I tripped over this by running a test case.
  2. Bombs out with above error.

Looking at the chunk of code (addWhereExistsQuery in Query/Builder.php), I'm not seeing where $operator ever got defined.

Most helpful comment

Just:

composer update

All 8 comments

This will be fixed in the next release.

Sweet, thank you.

That's running clean now.

Just:

composer update

Just:

composer update

you ruined my project. @ahlechandre

Just:

composer update

you ruined my project. @ahlechandre

git checkout composer.lock
composer install

@dyusip Thanks, it worked for me.
Can you answer why?

Was this page helpful?
0 / 5 - 0 ratings