diff --git a/src/Illuminate/Support/helpers.php b/src/Illuminate/Support/helpers.php index 62c8bb16aff7..673dba38f3d1 100755 --- a/src/Illuminate/Support/helpers.php +++ b/src/Illuminate/Support/helpers.php @@ -484,6 +484,14 @@ function data_set(&$target, $key, $value, $overwrite = true) } elseif ($overwrite || ! isset($target->{$segment})) { $target->{$segment} = $value; } + } else { + $target = []; + + if ($segments) { + data_set($target[$segment], $segments, $value, $overwrite); + } elseif ($overwrite) { + $target[$segment] = $value; + } } return $target; diff --git a/src/Illuminate/Validation/Validator.php b/src/Illuminate/Validation/Validator.php index 2b24fd96cbd4..74ff5d02ecd9 100755 --- a/src/Illuminate/Validation/Validator.php +++ b/src/Illuminate/Validation/Validator.php @@ -332,7 +332,7 @@ protected function initializeAttributeOnData($attribute) return $data; } - return data_fill($data, $attribute, null); + return data_set($data, $attribute, null, true); } /** diff --git a/tests/Support/SupportHelpersTest.php b/tests/Support/SupportHelpersTest.php index f91127ff74fe..e093ab50c9ae 100755 --- a/tests/Support/SupportHelpersTest.php +++ b/tests/Support/SupportHelpersTest.php @@ -502,6 +502,16 @@ public function testDataSet() ['foo' => ['bar' => 'boom'], 'baz' => 'kaboom'], data_set($data, 'foo.bar', 'boom') ); + + $this->assertEquals( + ['foo' => ['bar' => 'boom'], 'baz' => ['bar' => 'boom']], + data_set($data, 'baz.bar', 'boom') + ); + + $this->assertEquals( + ['foo' => ['bar' => 'boom'], 'baz' => ['bar' => ['boom' => ['kaboom' => 'boom']]]], + data_set($data, 'baz.bar.boom.kaboom', 'boom') + ); } public function testDataSetWithStar() diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index f26aa08d16e6..ac91c5a55c1d 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -2112,6 +2112,10 @@ public function testValidateImplicitEachWithAsterisksForRequiredNonExistingKey() { $trans = $this->getRealTranslator(); + $data = ['companies' => ['spark']]; + $v = new Validator($trans, $data, ['companies.*.name' => 'required']); + $this->assertFalse($v->passes()); + $data = ['names' => [['second' => 'I have no first']]]; $v = new Validator($trans, $data, ['names.*.first' => 'required']); $this->assertFalse($v->passes());