我验证一个模型
$validator=$c-
这是验证函数
public function validate($data){
return Validator::make($data, $this->rules());;
}
这些是规则
public function rules() {
return array([
'name' => [
'required', 'You need to choose a name for your collection.',
'unique:collections,table_name', 'A collection or collection table with this name already exists'
],
...
]);
}
我正在尝试发回一个带有验证程序错误的JSON响应,如下所示:
return response()->json($validator->errors(), 200);
我目前正在测试名称规则的验证,验证器如预期的那样失败。
但是,我希望它返回该规则的消息(“具有此名称的集合或集合表已经存在”)
取而代之的是,我得到了这个回复:
我的目标是让laravel发回我需要的错误,提前感谢您的帮助。
信息:
public function messages(){
return [
'name.required' => 'A name must be specified for the collection',
'name.unique' => 'A collection or collection table with this name already exists',
'name.min' => 'The collection name is too short',
'fields.*.fieldName.unique' => 'Field names must be unique',
'fields.*.fieldName.required' => 'One or more fields must be specified for the collection',
'fields.*.fieldName.not_in' => 'Illegal field name, please try another one',
'fields.*.fieldName.min' => 'The field name is too short',
'fields.*.dataType.required' => 'A data-type must be specified for fields',
'fields.*.dataType.in' => 'Illegal data-type'
];
}
public function rules() {
return array([
'name' => [
'required', 'You need to choose a name for your collection.',
'unique:collections,table_name', 'A collection or collection table
with this name already exists',
'min:2'
],
'fields.*.fieldName' =>
[
'unique' => 'Please ensure that the fields are uniquely named.',
'required' => 'You must specify a name for your fields.',
'not_in:'.implode(',', self::$illegalFieldNames),
'min:2'
],
'fields.*.dataType' =>
[
'required', 'You must specify a data type for your fields.',
'in:'.implode(',', self::$allowedDataTypes)
]
]);
}
public function validate($data){
return Validator::make($data, $this->rules(), $this->messages());
}
$this->rules($request, array(
'name' =>
'required|alpha_dash|min:5|max:255|unique:posts
));
使用java脚本显示错误
或者你可以用这样的东西。
public function store(Request $request)
$validator = Validator::make($request->all(), [
'title' => 'required|unique:posts|max:255',
'body' => 'required',
]);
if ($validator->fails()) {
return redirect('post/create')
->withErrors($validator)
->withInput();
}
// Store the blog post...
}
}
验证程序make
方法将第三个参数作为消息数组。你不能把规则和信息混为一谈。
public function rules()
{
return [
'name' => 'required|unique:collections,table_name'
];
}
public function messages()
{
return [
'name.required' => 'You need to choose a name for your collection',
'name.unique' => 'A collection or collection table with this name already exists',
];
}
public function validate($data)
{
return Validator::make($data, $this->rules(), $this->messages());
}
我是javascript新手,我试图创建一个简单的表单验证。当我点击提交按钮时,什么也没发生。我已经看了一段时间的例子,我似乎不知道我哪里出错了。有什么建议吗: 就在这篇文章之后,我要把它分解开来,开始变得更小。但与此同时,我想另一组眼睛不会受伤,很可能我做了什么可怕的错误。 我意识到我只是在上面扔了很多代码,所以提前感谢您筛选它。
状态{statuscode=network_error,resolution=null} 任何形式的帮助都将受到高度赞赏。
我用IntelliJ创建了一个非常简单的流测试。 IntelliJ无法完成测试,并给了我错误 这导致假设响应程序流不执行任何操作。 启动器流被执行。我可以看到这一点,因为命令显示在日志中。但是,我不知道响应器流是否从未由发起方流启动,或者只是没有响应。也许你可以帮我。 谢谢
我使用Jmeter对一个包括web套接字连接的应用程序进行负载测试。 当尝试使用单读取采样器读取帧中的数据时,得到错误响应代码:无响应响应消息:读取超时,未收到响应。 有人能帮我解决这个问题吗? 线程名称:密苏里州TestEnv 1-1样例开始时间:2019-10-09 10:40:43 IST加载时间:1000连接时间:0延迟时间:0大小以字节为单位:0发送字节:0头大小以字节为单位:0主体大小
堆栈跟踪:异常'Symfony\Component\Debug\Exc0019\FatalErrorExc0019'与消息'语法错误,意外'}"在D:\xampp\htdocs\guestlara\app\控制器\LoginController.php:23
我正在使用snake-case对我的API构建与springboot进行json映射。spring允许您在应用程序中轻松定义这一点。属性文件,其中包含: 这个很好用。但是,如果我添加了验证,并试图发布一个无效的json正文,那么响应消息将包含camel案例中缺少的字段。以下是我的控制器和传输对象: 控制器: 如果我发布以下json正文,一切正常:{“camel\u cased\u字段”:“test
我正在使用Selenium、C#、NUnit编写测试,有时会出现以下错误:- OpenQA。硒。WebDriverException:服务器没有响应url httö/löcalhost:7055/hub/session/8dd13f5c-7ca6-4aa6-babc-f0ff6d940f0a/element 下面是堆栈跟踪: OpenQA。硒。WebDriverException:服务器没有响应O
我有一个与 Rest Assured 中的响应正文验证相关的问题。让我们假设,我有一个像json这样的响应体。 我需要检查: 如果图书部分包含儿童类型 如果一本儿童类书籍的自动名称为Eric 第一个断言可以是这样的: 但是我需要检查它的作者的名字是否是威廉。有没有办法使用jsonPath检查它? 我假设,我可以做反序列化(例如,x. List