By default, Laravel validation errors will be returned in a list, checking all validation rules. But if you want the process to stop after the first error, use validation rule called bail
:
1$request->validate([2 'title' => 'bail|required|unique:posts|max:255',3 'body' => 'required',4]);
If you need to stop validation on the first error in FormRequest
class, you can set stopOnFirstFailure
property to true
:
1protected $stopOnFirstFailure = true;