I am upgrading my laravel
from 5.5
to 5.6
. and upon running tests, I am getting this error:
ErrorException: compact(): Undefined variable: operator
Now there is a solution present here Laravel – compact(): Undefined variable: operator in Builder.php but I am following that very solution and still facing that error. Earlier I was upgrading from 5.4
to 5.6
then upon seeing the solution mentioned in the above question, I upgraded from 5.4
to 5.5
and now trying to upgrade from 5.5
to 5.6
.
Here is a little piece of code that is causing this error:
$query = TransportOrder::with('orderNumber');
$query->whereHas('orderNumber', function ($q) use ($orderNumber) {
$q->where('order_number', '=', $orderNumber);
});
return $query->first();
That whereHas
is causing this problem. So is there an alternate to whereHas
and with
or there is any other solution that I am missing?
My php version is this:
PHP 7.3.23-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Oct 6 2020 11:36:27) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.23, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.23-1+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
with blackfire v1.24.2~linux-x64-non_zts73, https://blackfire.io, by Blackfire
EDIT:
compact()
is used in vendor
class Builder
:
public function addWhereExistsQuery(self $query, $boolean = 'and', $not = false)
{
$type = $not ? 'NotExists' : 'Exists';
$this->wheres[] = compact('type', 'operator', 'query', 'boolean');
$this->addBinding($query->getBindings(), 'where');
return $this;
}
2
Answers
As it turns out upgrading laravel to 6.5.40 did the trick, as the mentioned issue was not resolved in the earlier versions.
If:
explicitly define the PHP version on the Homestead.yaml file. This should be done on the sites property as such (each is a new line, of course):
map: test.appp
/home/vagrant/code/test/public
php: "7.1"