php - 从验证 MessageBag 中替换消息数组
问题描述
我有一个扩展 FormRequest 类的类,我想用新的消息数组替换整个消息数组
这是我成功获取旧消息但现在想用$uniqueMessages
数组替换现有 MessageBag 数组的方法
/**
* Configure the validator instance.
*
* @param \Illuminate\Validation\Validator $validator
* @return void
*/
public function withValidator($validator)
{
$validator->after(function ($validator) {
$validationMessages = $validator->errors()->getMessages();
$uniqueMessages = array_unique($validationMessages, SORT_REGULAR);
//Require Stuff that set $uniqueMessages array to the MessageBag
});
}
我知道我们可以使用它添加额外的消息$validator->errors()->add('field', 'Something is wrong with this field!');
但我想用新消息替换现有消息
解决方案
推荐阅读
- firebase - 如何将 Firebase 地图转换为飞镖地图?
- azure - 无法导入自动解释器
- c++ - 即使为其相关的 dll 正确生成了 lib 文件,CMake 生成的 MSVC 项目也找不到符号
- javascript - 引导程序 4 - javascript 主文件
- java - 使用 inputMap 过滤列表(List1)中的数据(键和值可能因每个请求而异)
- google-apps-script - 谷歌应用脚本日期解析出错
- rest - 用于搜索的 RESTful URL 样式指南
- angular - Angular 8 - 从拦截器内导航后的代码
- android - Flutter:任务':app:compileDebugKotlin'的执行失败
- php - Laravel 队列不遵守作业特定的超时