Confide自定义验证器 [英] Confide custom validator
本文介绍了Confide自定义验证器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用confide进行用户身份验证.我想通过laravel的Validator(用于名字和姓氏)类使用自定义规则,如
I am using confide for user authentication. I wanna use custom rules using laravel's Validator (for firstname and lastname) class as in
$validator = Validator::make($user, $this->rules[$ruleset]);
,然后使用$validator->passes()
进行检查.我该如何实现?
and check with $validator->passes()
. How can I achieve this?
推荐答案
首先创建您的自定义验证类.像这样:
First create your custom validation class. Something like this:
class CustomValidator
{
/**
* @return bool
*/
public function validateFirstname($attribute, $value, $parameters) {
{
// Do here your Firstname validation
...
}
/**
* @return bool
*/
public function validateLastname($attribute, $value, $parameters) {
{
// Do here your Lastname validation
...
}
}
然后注册新的验证规则.例如,在bootstrap/start.php
文件中添加:
Then register the new validation rules. For example at bootstrap/start.php
file add:
Validator::extend('firstname', 'CustomValidator@validateFirstname');
Validator::extend('lastname', 'CustomValidator@validateLastname');
然后,您可以在模型中使用新规则firtsname
和lastname
.
Then you can use the new rules firtsname
and lastname
in your models.
我希望它对您有用.
这篇关于Confide自定义验证器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文