From f411387c329c72b559244e0bbfc9819566d24e70 Mon Sep 17 00:00:00 2001 From: zidbih Date: Fri, 10 Oct 2025 12:28:28 +0000 Subject: [PATCH 1/2] Fix Arr::dot() to convert empty arrays to null --- src/Illuminate/Collections/Arr.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Illuminate/Collections/Arr.php b/src/Illuminate/Collections/Arr.php index 49b17766499a..6f4f0c0eb5fa 100644 --- a/src/Illuminate/Collections/Arr.php +++ b/src/Illuminate/Collections/Arr.php @@ -172,6 +172,11 @@ public static function dot($array, $prepend = '') if (is_array($value) && ! empty($value)) { $flatten($value, $newKey.'.'); } else { + + if (is_array($value) && empty($value)) { + $value = null; + } + $results[$newKey] = $value; } } From 1f2db14b935fa11bd0d79e839569a6c06e52d638 Mon Sep 17 00:00:00 2001 From: zidbih Date: Fri, 10 Oct 2025 13:01:09 +0000 Subject: [PATCH 2/2] Update Arr::dot() test to expect null for empty arrays --- tests/Support/SupportArrTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Support/SupportArrTest.php b/tests/Support/SupportArrTest.php index ab5c2f2150a7..13504fb65a37 100644 --- a/tests/Support/SupportArrTest.php +++ b/tests/Support/SupportArrTest.php @@ -217,10 +217,10 @@ public function testDot() $this->assertSame([], $array); $array = Arr::dot(['foo' => []]); - $this->assertSame(['foo' => []], $array); + $this->assertSame(['foo' => null], $array); $array = Arr::dot(['foo' => ['bar' => []]]); - $this->assertSame(['foo.bar' => []], $array); + $this->assertSame(['foo.bar' => null], $array); $array = Arr::dot(['name' => 'taylor', 'languages' => ['php' => true]]); $this->assertSame(['name' => 'taylor', 'languages.php' => true], $array); @@ -243,7 +243,7 @@ public function testDot() $array = Arr::dot(['foo' => 'bar', 'empty_array' => [], 'user' => ['name' => 'Taylor'], 'key' => 'value']); $this->assertSame([ 'foo' => 'bar', - 'empty_array' => [], + 'empty_array' => null, 'user.name' => 'Taylor', 'key' => 'value', ], $array);