diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index 2d0ec3ec37fe..24ab0e4e95ab 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -193,7 +193,7 @@ public function whereKey($id) return $this; } - if ($this->model->getKeyType() === 'string') { + if ($id !== null && $this->model->getKeyType() === 'string') { $id = (string) $id; } @@ -214,7 +214,7 @@ public function whereKeyNot($id) return $this; } - if ($this->model->getKeyType() === 'string') { + if ($id !== null && $this->model->getKeyType() === 'string') { $id = (string) $id; } diff --git a/src/Illuminate/Foundation/Application.php b/src/Illuminate/Foundation/Application.php index 3ef3a2eb4818..28109474e5c9 100755 --- a/src/Illuminate/Foundation/Application.php +++ b/src/Illuminate/Foundation/Application.php @@ -33,7 +33,7 @@ class Application extends Container implements ApplicationContract, CachesConfig * * @var string */ - const VERSION = '7.26.0'; + const VERSION = '7.26.1'; /** * The base path for the Laravel installation. diff --git a/tests/Database/DatabaseEloquentBuilderTest.php b/tests/Database/DatabaseEloquentBuilderTest.php index cbccc88ba216..07b3ff8185e9 100755 --- a/tests/Database/DatabaseEloquentBuilderTest.php +++ b/tests/Database/DatabaseEloquentBuilderTest.php @@ -1063,6 +1063,19 @@ public function testWhereKeyMethodWithStringZero() $builder->whereKey($int); } + public function testWhereKeyMethodWithStringNull() + { + $model = new EloquentBuilderTestStubStringPrimaryKey(); + $builder = $this->getBuilder()->setModel($model); + $keyName = $model->getQualifiedKeyName(); + + $builder->getQuery()->shouldReceive('where')->once()->with($keyName, '=', m::on(function ($argument) { + return $argument === null; + })); + + $builder->whereKey(null); + } + public function testWhereKeyMethodWithArray() { $model = $this->getMockModel(); @@ -1102,6 +1115,19 @@ public function testWhereKeyNotMethodWithStringZero() $builder->whereKeyNot($int); } + public function testWhereKeyNotMethodWithStringNull() + { + $model = new EloquentBuilderTestStubStringPrimaryKey(); + $builder = $this->getBuilder()->setModel($model); + $keyName = $model->getQualifiedKeyName(); + + $builder->getQuery()->shouldReceive('where')->once()->with($keyName, '!=', m::on(function ($argument) { + return $argument === null; + })); + + $builder->whereKeyNot(null); + } + public function testWhereKeyNotMethodWithInt() { $model = $this->getMockModel();