Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Inconsistent validation behavior with empty arrays and nested rules #55657

Copy link
Copy link
Open
@comhon-project

Description

@comhon-project
Issue body actions

Laravel Version

11.44.2

PHP Version

8.3

Database Driver & Version

No response

Description

Hello everyone,

I've noticed an unexpected behavior when validating empty arrays with nested rules.

Here’s an example without any nested rules, which works as expected:

$validated = Validator::validate(['foo' => []], [
    'foo' => 'present|array',
]);
// $validated contains the "foo" key:  ["foo" => []]

However, when I add a nested rule:

$validated = Validator::validate(['foo' => []], [
    'foo' => 'present|array',
    'foo.bar' => 'integer'
]);
// $validated is empty: []

Expected:
the validated values should be the same and contain the "foo" key, since "foo.bar" is not required.

Steps To Reproduce

$validated = Validator::validate(['foo' => []], [
    'foo' => 'present|array',
]);
// $validated contains the "foo" key:  ["foo" => []]

$validated = Validator::validate(['foo' => []], [
    'foo' => 'present|array',
    'foo.bar' => 'integer'
]);
// $validated is empty: []

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.