Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional callback for ArrayValidator. #4311

Closed
wants to merge 1 commit into from
Closed

Add optional callback for ArrayValidator. #4311

wants to merge 1 commit into from

Conversation

timkelty
Copy link
Contributor

This may be a stretch, as I'm not sure there is an immediate use for it, but I found it helpful authoring a plugin.

If not, at least I can extend ArrayValidator and add it now that #4309 is fixed.

Example usage (validating an attribute is an array of MyModels):

    public function rules()
    {
        return [
            ['myModels', ArrayValidator::class, 'callback' => function ($value) {
                return $value instanceof MyModel;
            }],
        ];
    }

@brandonkelly
Copy link
Member

Hm yeah I don’t think there’s any precedence for this. You could always just check for errors on the model attribute after validate and do whatever you need to do with them from there, or write your own validation method.

@timkelty
Copy link
Contributor Author

Yep, sounds good 🤠.

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.

2 participants