Is there any possibility to set FormRequest
rules to default use bail
rule without typing in it?
Instead of:
class StoreRequest extends FormRequest {
function rules() {
return [
'name' => 'bail|required|min:3',
'last_name' => 'bail|required|min:3',
'names' => 'bail|required|min:3',
'email' => 'bail|required|email',
'type' => 'integer|min:10|max:50',
// [...]
];
}
}
I would like to get more cleaner version, like:
class StoreRequest extends FormRequest {
protected $stopsOnFirstError = true; // I can't find anything like this
function rules() {
return [
'name' => 'required|min:3',
'last_name' => 'required|min:3',
'names' => 'required|min:3',
'email' => 'required|email',
'type' => 'integer|min:10|max:50',
// [...]
];
}
}
Update:
Some of my rules are defined as array:
'type' => [
'bail',
'required',
'integer',
Rule::in(ContactType::getValues()),
],
bail
is already implicit with therequired
rule so it is not necessary. Howeverbail
will not work in preventing other fields from validating it only stops the other validation rules on the one field it's validating. – Pinfold