Skip to content

Conversation

elyass-dehghan
Copy link
Contributor

This pull request fixes an issue where the validateDigits method throws a TypeError when the validated attribute value is an array instead of a string.

Previously:

preg_match('/^\d{'.$parameters[0].'}$/', $value);

would throw:

preg_match(): Argument #2 ($subject) must be of type string, array given

Now, the method ensures that the value is a string before running the validation, preventing framework-level exceptions and keeping behavior consistent with other validation rules.

Example case:

$request->validate([
    'code' => 'digits:4',
]);

If the request accidentally sends code[], Laravel will now gracefully handle the invalid type instead of throwing an error.

Impact:
This change improves robustness of the validation system by preventing a framework exception and instead treating the case as a simple validation failure.

@macropay-solutions
Copy link

Just as a note this can be prevented

$request->validate([
    'code' => 'numeric|digits:4',
]);

@taylorotwell taylorotwell merged commit 8133184 into laravel:12.x Oct 21, 2025
49 of 66 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants