Skip to content

Better docmentation / example for unnamed values / items #18

Description

@th-lange

Requirement:

I want to validate an array of objects, like:

[
    {
        "foo": "foo1",
        "bar": "bar1",
        "baz": "baz1"
    },
    {
        "foo": "foo2",
        "bar": "bar2",
        "baz": "baz2"
    },
    {
        "foo": "foo3",
        "bar": "bar3",
        "baz": "baz3"
    }
]

So I tried this:

        $validator = new Validator();
        $rules = RulesBuilder::create()
            ->rule('collection', RulesBuilder::create()
                ->field('foo', 'required')
                ->field('bar', 'required')
                ->field('baz', 'required')
                ->build()
            )->build();

But I get the error:
array_shift() expects parameter 1 to be array, string given
vendor/philiplb/valdi/src/Valdi/Validator.php:131

It would be nice, to get an example on how to validate "unnamed" collections.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions