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

feat: allow overriding the validation process #105

Closed
wants to merge 1 commit into from

Conversation

SychO9
Copy link
Contributor

@SychO9 SychO9 commented Mar 14, 2024

Hello 👋🏼,

In our use case we wish to validate all the fields together to enable certain validation capabilities in illuminate/validation (such as required_with). But also, we want to entirely rely on illuminate/validation.

Opening up the assertDataValid for overriding would allow for this to be possible.

@tobyzerner
Copy link
Owner

I'm wary of opening up the private methods of the SavesData trait at this stage, since the way they're structured feels somewhat arbitrary (like an implementation detail) and opening them up would mean any refactoring in the future would require a major version bump. It's still something I need to think about in more depth.

In the meantime what about these options?

  • If I added the $data array to the Context object, could you write a custom rules helper which passes in all of the data to the validator for each field, so that cross-field rules like required_with will work?
  • Or, could you subclass Attribute to add your rules methods, and then perform validation in the Resource class's create and update methods?

What do you think?

@tobyzerner tobyzerner closed this Mar 30, 2024
@SychO9
Copy link
Contributor Author

SychO9 commented Mar 30, 2024

Totally understandable!

could you write a custom rules helper which passes in all of the data to the validator for each field, so that cross-field rules like required_with will work?

helper might be limiting compared to the API we ended up with, but will see.

Or, could you subclass Attribute to add your rules methods, and then perform validation in the Resource class's create and update methods?

would move validation after field setters i believe, which is too strong a change.

However, we can always just rely on custom Create/Update endpoints instead (that's how it was implemented prior to the fork) so that's not a blocker.

@SychO9 SychO9 deleted the sm/extend-validation-process branch March 30, 2024 11:16
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