From dba7c5daf60bd3104e9639e93f7bbe900c5fa77a Mon Sep 17 00:00:00 2001 From: ianrobertsFF <91917328+ianrobertsFF@users.noreply.github.com> Date: Fri, 6 Jan 2023 18:39:06 +0000 Subject: [PATCH 1/2] feat: Update Error Bag on response exception - Updates the Error Bag on the exception attached to the response, in addition to the response data - Allows any other middleware executing after TransformsFlexibleErrors that interacts with the Exception/Validator directly to use the correct keys --- src/Http/TransformsFlexibleErrors.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Http/TransformsFlexibleErrors.php b/src/Http/TransformsFlexibleErrors.php index e83d260c..1253333e 100644 --- a/src/Http/TransformsFlexibleErrors.php +++ b/src/Http/TransformsFlexibleErrors.php @@ -30,11 +30,15 @@ protected function shouldTransformFlexibleErrors(Response $response) */ protected function transformFlexibleErrors(Response $response) { - $response->setData( - $this->updateResponseErrors($response->original) - ); + $updatedResponseErrors = $this->updateResponseErrors($response->original); - return $response; + $errorBag = $response->exception?->validator?->errors(); + if ($errorBag instanceof MessageBag) { + $replaceMessages = function (array $messages) { $this->messages = $messages; }; + $replaceMessages->call($errorBag, $updatedResponseErrors['errors']); + } + + return $response->setData($updatedResponseErrors); } /** From e9d96550a9f4a2a4f9925fe917afd22877a9a728 Mon Sep 17 00:00:00 2001 From: ianrobertsFF <91917328+ianrobertsFF@users.noreply.github.com> Date: Fri, 6 Jan 2023 18:40:38 +0000 Subject: [PATCH 2/2] fix: include message bag --- src/Http/TransformsFlexibleErrors.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Http/TransformsFlexibleErrors.php b/src/Http/TransformsFlexibleErrors.php index 1253333e..7e28bda5 100644 --- a/src/Http/TransformsFlexibleErrors.php +++ b/src/Http/TransformsFlexibleErrors.php @@ -7,6 +7,7 @@ use Illuminate\Support\Str; use Symfony\Component\HttpFoundation\Response; use Whitecube\NovaFlexibleContent\Flexible; +use Illuminate\Contracts\Support\MessageBag; trait TransformsFlexibleErrors {