要向Laravel添加新的验证,我已经完成了这一步:
做了一个所谓的新文件customValidation.php
中app/start/
然后将其包含进来,app/start/global.php
并使用进行了测试,echo()
并且该方法有效。因此,现在将其加载到应用程序中。
然后,我编写了以下代码来验证Laravel中的复选框:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
class customValidate extends Illuminate\Validation\Validator
{
public function validateCheckbox($attribute, $value, $parameters)
{
//if(isset($value)) { return true; } else { return true; }
echo "this is the: " . $value;
}
}
/**
* Resolvers for Custom Validations
*/
Validator::resolver(function($translator, $data, $rules, $message){
return new customValidate($translator, $data, $rules, $message);
});
但是,在验证规则中,我定义了:
`array('sex'=>'checkbox')`
但这是行不通的。什么都没发生。没有引发任何错误。该应用程序的行为就像完全没有执行该功能一样。同样,当我从函数内部回显某些内容时,什么也没有得到回显,这是该函数根本没有被调用的另一个证据。
提交表单时,收音机未设置为初始状态,这使Laravel无需寻找商品的验证者。因此,它没有任何解决方法。我所做的是,我只是向收音机添加了初始状态,然后收音机开始工作了。
很像Andreyco所说
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句