Skip to content

Validation: failed dependent rule message uses lowercase #57678

@RobertWeideKyos

Description

@RobertWeideKyos

Laravel Version

12.37.0

PHP Version

8.4.14

Database Driver & Version

No response

Description

When validating using rules that depend on other fields (like required_if or prohibited_if), the failed message contains a lower case string of the passed in value. This is confusing if the value that was checked against is not lower case. It is also confusing that the passed in value is used, rather then the value that it was checked against.

Steps To Reproduce

use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;

$correct = Validator::make(['field1' => 'aa'], ['field1' => 'required', 'field2' => 'required_if:field1,AA', 'field3' => 'required_if:field1,aa']);

// Will output "The field3 field is required when field1 is aa."
$correct->validate();

$wrong = Validator::make(['field1' => 'AA'], ['field1' => 'required', 'field2' => 'required_if:field1,AA', 'field3' => 'required_if:field1,aa']);

// Will output "The field2 field is required when field1 is aa." (Note the case).
$wrong->validate();

// Special edge case
$wrong = Validator::make(['field1' => 'False'], ['field1' => ['required', 'boolean'], 'field2' => 'required_if:field1,true']);

// Will output "The field1 field must be true or false. (and 1 more error)."
$wrong->validate(); 

// Returns "The field2 field is required when field1 is false." (But the rule checks for true).
$wrong->errors()->get('field2');

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions