Skip to content

Commit a2878e9

Browse files
committed
Undo array-based nested error bag support
1 parent fb8616a commit a2878e9

File tree

2 files changed

+4
-34
lines changed

2 files changed

+4
-34
lines changed

src/ServiceProvider.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,7 @@ protected function shareValidationErrors()
6464
Inertia::share('errors', function () {
6565
$errors = Session::get('errors', new ViewErrorBag());
6666

67-
if (is_array($errors) && count($errors) > 0 && is_array($errors[array_keys($errors)[0]])) {
68-
$errors = tap(new ViewErrorBag(), function ($bag) use ($errors) {
69-
foreach ($errors as $key => $messages) {
70-
$bag->put($key, new MessageBag($messages));
71-
}
72-
});
73-
} elseif (is_array($errors) && count($errors) > 0) {
67+
if (is_array($errors) && count($errors) > 0) {
7468
$errors = (new ViewErrorBag())->put('default', new MessageBag($errors));
7569
} elseif ($errors instanceof MessageBag && $errors->any()) {
7670
$errors = (new ViewErrorBag())->put('default', $errors);

tests/ServiceProviderTest.php

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -117,22 +117,9 @@ public function test_validation_errors_are_returned_in_the_correct_format($error
117117
$this->assertSame('The email must be a valid email address.', $errors->email);
118118
}
119119

120-
public function multipleErrorBagsValidationErrorsProvider()
120+
public function test_validation_exceptions_can_have_multiple_error_bags()
121121
{
122-
$array = [
123-
'default' => [
124-
'name' => [
125-
'The name field is required.',
126-
],
127-
'email' => 'The email must be a valid email address.',
128-
],
129-
'example' => [
130-
'name' => 'The name field is required.',
131-
'email' => 'The email must be a valid email address.',
132-
],
133-
];
134-
135-
$viewErrorBag = tap(new ViewErrorBag(), function ($errorBag) {
122+
Session::put('errors', tap(new ViewErrorBag(), function ($errorBag) {
136123
$errorBag->put('default', new MessageBag([
137124
'name' => 'The name field is required.',
138125
'email' => 'The email must be a valid email address.',
@@ -143,18 +130,7 @@ public function multipleErrorBagsValidationErrorsProvider()
143130
'The email must be a valid email address.',
144131
],
145132
]));
146-
});
147-
148-
return [
149-
[$array],
150-
[$viewErrorBag],
151-
];
152-
}
153-
154-
/** @dataProvider multipleErrorBagsValidationErrorsProvider */
155-
public function test_validation_exceptions_can_have_multiple_error_bags($errors)
156-
{
157-
Session::put('errors', $errors);
133+
}));
158134

159135
$errors = Inertia::getShared('errors')();
160136

0 commit comments

Comments
 (0)