In my custom Request, in the rules method, I'm checking a few things before returning the rules array.
I would like to make the validation fail as soon as I found some errors I can't check by the default validation rules.
So I would like to have something like this:
public function rules() {
$rules = [
'first_parameter' => 'required'
];
if( someErrorCondition ) {
// here i would like to make the rules method always fail the validation
}
return $rules;
}
What's the best approach to deal with it?
而是创建一个自定义验证规则 。
You're using the complete wrong method.
Your rules list is a basic list of rules to perform validation on.
For additional logic, either add it into the controller (at the expense of your sanity later on), or use a custom rule .
If you need to restrict users based on permissions, etc. then use the authorize
method.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.