| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2028d82 commit d8da8eb
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -166,8 +166,12 @@ public function __construct(TranslatorInterface $translator, array $data, array | |||
| 166 | 166 | $this->translator = $translator; | |
| 167 | 167 | $this->customMessages = $messages; | |
| 168 | 168 | $this->data = $this->parseData($data); | |
| 169 | - $this->rules = $this->explodeRules($rules); | ||
| 170 | 169 | $this->customAttributes = $customAttributes; | |
| 170 | + | ||
| 171 | + // Explode the rules first so that the implicit ->each calls are made... | ||
| 172 | + $rules = $this->explodeRules($rules); | ||
| 173 | + | ||
| 174 | + $this->rules = array_merge((array) $this->rules, $rules); | ||
| 171 | 175 | } | |
| 172 | 176 | ||
| 173 | 177 | /** | |
@@ -209,8 +213,14 @@ protected function parseData(array $data, $arrayKey = null) | |||
| 209 | 213 | */ | |
| 210 | 214 | protected function explodeRules($rules) | |
| 211 | 215 | { | |
| 212 | - foreach ($rules as $key => &$rule) { | ||
| 213 | - $rule = (is_string($rule)) ? explode('|', $rule) : $rule; | ||
| 216 | + foreach ($rules as $key => $rule) { | ||
| 217 | + if (Str::contains($key, '*')) { | ||
| 218 | + $this->each($key, $rule); | ||
| 219 | + | ||
| 220 | + unset($rules[$key]); | ||
| 221 | + } else { | ||
| 222 | + $rules[$key] = (is_string($rule)) ? explode('|', $rule) : $rule; | ||
| 223 | + } | ||
| 214 | 224 | } | |
| 215 | 225 | ||
| 216 | 226 | return $rules; | |
@@ -261,22 +271,14 @@ public function sometimes($attribute, $rules, callable $callback) | |||
| 261 | 271 | */ | |
| 262 | 272 | public function each($attribute, $rules) | |
| 263 | 273 | { | |
| 264 | - $data = Arr::get($this->data, $attribute); | ||
| 274 | + $data = Arr::dot($this->data); | ||
| 265 | 275 | ||
| 266 | - if (! is_array($data)) { | ||
| 267 | - if ($this->hasRule($attribute, 'Array')) { | ||
| 268 | - return; | ||
| 269 | - } | ||
| 270 | - | ||
| 271 | - throw new InvalidArgumentException('Attribute for each() must be an array.'); | ||
| 272 | - } | ||
| 273 | - | ||
| 274 | - foreach ($data as $dataKey => $dataValue) { | ||
| 275 | - foreach ((array) $rules as $ruleKey => $ruleValue) { | ||
| 276 | - if (! is_string($ruleKey)) { | ||
| 277 | - $this->mergeRules("$attribute.$dataKey", $ruleValue); | ||
| 278 | - } else { | ||
| 279 | - $this->mergeRules("$attribute.$dataKey.$ruleKey", $ruleValue); | ||
| 276 | + foreach ($data as $key => $value) { | ||
| 277 | + if (Str::startsWith($key, $attribute) || Str::is($attribute, $key)) { | ||
| 278 | + foreach ((array) $rules as $ruleKey => $ruleValue) { | ||
| 279 | + if (! is_string($ruleKey) || Str::endsWith($key, $ruleKey)) { | ||
| 280 | + $this->mergeRules($key, $ruleValue); | ||
| 281 | + } | ||
| 280 | 282 | } | |
| 281 | 283 | } | |
| 282 | 284 | } | |
@@ -1655,7 +1657,7 @@ protected function getCustomMessageFromTranslator($customKey) | |||
| 1655 | 1657 | { | |
| 1656 | 1658 | $shortKey = str_replace('validation.custom.', '', $customKey); | |
| 1657 | 1659 | ||
| 1658 | - $customMessages = array_dot( | ||
| 1660 | + $customMessages = Arr::dot( | ||
| 1659 | 1661 | (array) $this->translator->trans('validation.custom') | |
| 1660 | 1662 | ); | |
| 1661 | 1663 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1788,9 +1788,6 @@ public function testValidateEachWithNonArrayWithArrayRule() | |||
| 1788 | 1788 | $this->assertFalse($v->passes()); | |
| 1789 | 1789 | } | |
| 1790 | 1790 | ||
| 1791 | - /** | ||
| 1792 | - * @expectedException InvalidArgumentException | ||
| 1793 | - */ | ||
| 1794 | 1791 | public function testValidateEachWithNonArrayWithoutArrayRule() | |
| 1795 | 1792 | { | |
| 1796 | 1793 | $trans = $this->getRealTranslator(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments