我正在使用引导验证器创建一个表单。我正在使用引导验证器(客户端)和 laravel 验证(服务器)执行验证。我的问题是我想向 laravel 执行 ajax 请求以检查用户名的可用性。
在 laravel 中,我们有这种类型的验证:
'username' => 'required|min:6|max:15|unique:users',
检查用户名的可用性。现在我想在引导验证器中包含这种类型的检查。
username: {
validators: {
notEmpty: {
message: 'The username is required and cannot be empty'
},
stringLength: {
min: 6,
max: 15,
message: 'The username must be more than 6 and less than 15 characters long'
},
regexp: {
regexp: /^[a-zA-Z0-9_\.]+$/,
message: 'The username can only consist of alphabetica, number, dot and underscore'
},
remote: {
url: '' /*** how can I perform laravel validation with this?
message: 'The username is not available'
}
}
},
我怎样才能做到这一点?我是否需要为此类检查创建自定义助手?或者我可以将 laravel 的验证与此集成吗?