protected function whenValidated($messageBag, $sendHeaders)
    {
        $messages = empty($messageBag) ? [] : $messageBag->getMessages();
        if ($this->request->ajax() && $sendHeaders) {
            $return = [];
            foreach ($messages as $key => $phrases) {
                if (str_contains($key, '[]')) {
                    $key = str_replace(['[', ']'], '_', $key);
                }
                $return[$key] = $phrases;
            }
            return $this->response($return);
        }
        if (!empty($messages)) {
            $this->messageBag = $messageBag;
            return false;
        }

        return true;
    }