dom*_*rap 5 php validation laravel laravel-3
在尝试实现基于Laravel长度的验证时
'password' => array(
'required',
'alpha_dash',
'Min:7'
)
Run Code Online (Sandbox Code Playgroud)
并在我的视图中输出错误消息
{{
$errors->first(
'password',
'<span class="error">:message</span>'
)
}}
Run Code Online (Sandbox Code Playgroud)
我明白了
Unhandled Exception
Message:
Array to string conversion
Location:
_avalog\laravel\messages.php on line 188
Stack Trace:
#0 _avalog\laravel\laravel.php(42): Laravel\Error::native(8, 'Array to string...', '_avalog...', 188)
#1 [internal function]: Laravel\{closure}(8, 'Array to string...', '_avalog...', 188, Array)
#2 _avalog\laravel\messages.php(188): str_replace(':message', Array, 'get('password', 'get()
Run Code Online (Sandbox Code Playgroud)
调试,似乎是真的.如果我print_r( $validation );
Laravel\Validator Object (
[attributes] => Array (
[username] => fred
[email] =>
[password] => asd
[csrf_token] => DWg3CUfqtMZkIRfyZXNEqygvWUHsGS9SQMue2V4S
)
[errors] => Laravel\Messages Object (
[messages] => Array (
[email] => Array (
[0] => The email field is required.
)
[password] => Array (
[0] => Array (
[numeric] => The password must be at least 7.
[file] => The password must be at least 7 kilobytes.
[string] => The password must be at least 7 characters.
)
)
)
[format] => :message
)
Run Code Online (Sandbox Code Playgroud)
你可以看到消息实际上包含一个密码数组,它似乎依赖于输入类型,即使我在规则中指定它是alphadash
[password] => Array (
[0] => Array (
[numeric] => The password must be at least 7.
[file] => The password must be at least 7 kilobytes.
[string] => The password must be at least 7 characters.
)
)
Run Code Online (Sandbox Code Playgroud)
而其余的,不要
[email] => Array (
[0] => The email format is invalid.
)
Run Code Online (Sandbox Code Playgroud)
看着messages.php在Laravel框架,它没有任何处理这种基于阵列的消息,所以我认为我做的事情错了,它到那里之前,但我不知道是什么.
谢谢你的帮助.
Mir*_*kov 14
您的规则条目有误.它必须是
'password' => 'required|alpha_dash|min:7'
Run Code Online (Sandbox Code Playgroud)
查看Laravel验证文档以获取更多信息
| 归档时间: |
|
| 查看次数: |
25904 次 |
| 最近记录: |