Framework: Validation rule bail not working

Created on 7 Feb 2017  路  3Comments  路  Source: laravel/framework

  • Laravel Version: 5.4.7
  • PHP Version: 7.1.0
  • Database Driver & Version: 5.7.16

Steps to reproduce

  1. Make validator with rules [ 'email' => 'bail|required_if:status_id,2|email' ];
  2. Submit form with status_id = 3 and wrong format email

What is Expected?

Validation passes succesfully.

What is actually happening?

Validator throws error The email must be a valid email address.

Most helpful comment

All 3 comments

Why do you think the validator should pass? Bail stops further validation if the first rule fails, in your example the first rule was skipped because status_id <> 2, so the actual first rule hit was email since the required_if was skipped.

But, how i can check email only if previous rules passed, i.e i want to check email only if status_id = 2?
Advice me plz 馃槂

Was this page helpful?
0 / 5 - 0 ratings