Answer the question
In order to leave comments, you need to log in
What is the meaning of bail in Laravel?
The Laravel validator has a bail rule.
Here's how it's described in the documentation:
Sometimes it is necessary to stop executing the input validation rules for an attribute after the first error. To do this, assign a bail rule to the attribute:
$this->validate($request, [ 'title' => 'bail|required|unique:posts|max:255', 'body' => 'required', ]);
If the required rule on the title attribute fails, then the unique rule will not be checked. The rules will be checked in the order they are assigned.
Answer the question
In order to leave comments, you need to log in
This in the case of required is not checked if the field is not set. Otherwise, all rules are checked. bail allows you to stop at the first failure. The documentation is not a very good example, it seems.
For example, if the field is filled, then uniqueness is checked. If bail is present, then max will not be checked in case of uniqueness failure. Otherwise it will.
In order not to receive 5 errors for each field at the same time.
In terms of design, it's bad.
But in terms of usability, it infuriates when they write one error, and you don’t know what rules you still need to follow, and you send the form 50 times to go through all the errors. Here is a bail about it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question