diff --git a/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php b/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php index 5efe0b5f2234..38ac9cb3b43e 100755 --- a/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php +++ b/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php @@ -301,11 +301,15 @@ protected function wrapValue($value) */ protected function wrapJsonSelector($value) { - $path = explode('->', $value); + $delimiter = str_contains($value, '->>') + ? '->>' + : '->'; + + $path = explode($delimiter, $value); $field = $this->wrapSegments(explode('.', array_shift($path))); - return sprintf('%s->\'$.%s\'', $field, collect($path)->map(function ($part) { + return sprintf('%s'.$delimiter.'\'$.%s\'', $field, collect($path)->map(function ($part) { return '"'.$part.'"'; })->implode('.')); } diff --git a/tests/Database/DatabaseQueryBuilderTest.php b/tests/Database/DatabaseQueryBuilderTest.php index 6a1401350490..41f6b62f33f8 100755 --- a/tests/Database/DatabaseQueryBuilderTest.php +++ b/tests/Database/DatabaseQueryBuilderTest.php @@ -2023,6 +2023,15 @@ public function testMySqlWrappingJsonWithBooleanAndIntegerThatLooksLikeOne() $this->assertEquals('select * from `users` where `items`->\'$."available"\' = true and `items`->\'$."active"\' = false and `items`->\'$."number_available"\' = ?', $builder->toSql()); } + public function testMySqlWrappingJsonWithoutQuote() + { + $builder = $this->getMySqlBuilder(); + $builder->select('*')->from('users')->where('items->>sku', '=', 'foo-bar'); + $this->assertEquals('select * from `users` where `items`->>\'$."sku"\' = ?', $builder->toSql()); + $this->assertCount(1, $builder->getRawBindings()['where']); + $this->assertEquals('foo-bar', $builder->getRawBindings()['where'][0]); + } + public function testMySqlWrappingJson() { $builder = $this->getMySqlBuilder();