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

Support after validation hook Laravel #2156

Open
muhghazaliakbar opened this issue Jun 6, 2022 · 3 comments
Open

Support after validation hook Laravel #2156

muhghazaliakbar opened this issue Jun 6, 2022 · 3 comments
Labels
enhancement A feature or improvement

Comments

@muhghazaliakbar
Copy link

I have checked the docs about: https://laravel.com/docs/9.x/validation#after-validation-hook but I think this feature isn't available yet, it would be really good if Lighthouse supported this feature

@spawnia spawnia added the enhancement A feature or improvement label Jun 7, 2022
@spawnia
Copy link
Collaborator

spawnia commented Jun 7, 2022

I could see extending @validate like this:

"""
Run validation on a field.
"""
directive @validate(
  """
  References functions that receive the `Illuminate\Contracts\Validation\Validator` after validation is completed.
  Consists of two parts: a class name and a method name, seperated by an `@` symbol.
  If you pass only a class name, the method name defaults to `__invoke`.
  """
  after: [String!]
) on FIELD_DEFINITION

If you want to add a pull request to support this feature, consider https://github.com/nuwave/lighthouse/blob/master/CONTRIBUTING.md. Tests should be added to https://github.com/nuwave/lighthouse/blob/master/tests/Integration/Validation/ValidationTest.php.

@grimxd
Copy link

grimxd commented Jun 8, 2022

Maybe something like withValidator also for the Validator classes

@nuwave nuwave deleted a comment from muhghazaliakbar Jun 10, 2022
@LarsaSolidor
Copy link

Having the withValidator hook available after the main validation has been completed would be useful for us. We need to run validation on a field that might not have been provided to see whether it should have been or not in the context of other input parameters.

Currently, it seems that if a field hasn't been provided in the request, and it's not marked as required in the validator, no validation gets run on it at all, including any custom validator classes. The withValidator hook would allow us to get around this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A feature or improvement
Projects
None yet
Development

No branches or pull requests

4 participants