diff --git a/src/Http/TransformsFlexibleErrors.php b/src/Http/TransformsFlexibleErrors.php index e83d260c..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 { @@ -30,11 +31,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); } /**