Laravel验证未显示错误 [英] Laravel validation not showing errors
问题描述
这可能是一个简单的解决方法...但是我无法通过验证来工作.
This is probably a simple fix... but I can't get validation to work.
我已将测试简化为此...
I've simplified my test back to this...
$input = array(
'name' => ''
);
$rules = array(
'name' => 'required|min:3|max:50|alpha'
);
$v = Validator::make($input, $rules);
即使'name'是必需的并且具有所有其他规则,验证器也不会包含任何错误.
And even though 'name' is required and has all the other rules the validator doesn't contain any errors.
dd($v->errors); // returns NULL
但是
dd($v->fails()); // returns bool(true)
为什么没有错误消息?当我转储整个$ v对象时,在任何地方都看不到任何消息.非常困惑.帮助表示赞赏.谢谢.
Why are there no error messages? When I dump the whole $v object there are no messages to be seen anywhere. Very confused... help appreciated. Thanks.
----编辑
我进一步简化了这个过程. 我将其直接用于测试...
I've simplified this even further. I've put this directly in a view to test...
<?php
$input = array(
'name' => ''
);
$rules = array(
'name' => 'required'
);
$v = Validator::make($input, $rules);
dd($v);
?>
我仍然遇到完全相同的问题吗?
I still get exactly the same problem?
这是$ v对象
object(Laravel\Validator)#32 (9) {
["attributes"]=>
array(1) {
["name"]=>
string(0) ""
}
["errors"]=>
NULL
["rules":protected]=>
array(1) {
["name"]=>
array(1) {
[0]=>
string(8) "required"
}
}
["messages":protected]=>
array(0) {
}
["db":protected]=>
NULL
["bundle":protected]=>
string(11) "application"
["language":protected]=>
NULL
["size_rules":protected]=>
array(4) {
[0]=>
string(4) "size"
[1]=>
string(7) "between"
[2]=>
string(3) "min"
[3]=>
string(3) "max"
}
["numeric_rules":protected]=>
array(2) {
[0]=>
string(7) "numeric"
[1]=>
string(7) "integer"
}
}
我的安装/设置中的某些东西坏了吗?
Is something in my installation/setup broken?
推荐答案
在出现任何错误之前,您必须测试Validator.试试这个:
You have to test your Validator before there are any errors. Try this:
if ($v->fails()) {
dd($v->errors);
}
这篇关于Laravel验证未显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!