Skip to content
This repository was archived by the owner on Feb 10, 2019. It is now read-only.

Add hook for validator before resolution #269

Merged
merged 1 commit into from
Feb 1, 2018
Merged

Add hook for validator before resolution #269

merged 1 commit into from
Feb 1, 2018

Conversation

hailwood
Copy link
Contributor

The same as you can use the withValidator method on form requests, we can now do that with mutations.

From the Laravel docs on this method on form requests:

If you would like to add an "after" hook to a form request, you may use the withValidator method. This method receives the fully constructed validator, allowing you to call any of its methods before the validation rules are actually evaluated:

/**
 * Configure the validator instance.
 *
 * @param  \Illuminate\Validation\Validator  $validator
 * @return void
 */
public function withValidator($validator)
{
    $validator->after(function ($validator) {
        if ($this->somethingElseIsInvalid()) {
            $validator->errors()->add('field', 'Something is wrong with this field!');
        }
    });
}

Additionally we're also passing through the $args as the second parameter.

The same as you can use the `withValidator` method on form requests, we can now do that with mutations.

From the Laravel docs on this method on form requests:

> If you would like to add an "after" hook to a form request, you may use the withValidator method. This method receives the fully constructed validator, allowing you to call any of its methods before the validation rules are actually evaluated:

```php
/**
 * Configure the validator instance.
 *
 * @param  \Illuminate\Validation\Validator  $validator
 * @return void
 */
public function withValidator($validator)
{
    $validator->after(function ($validator) {
        if ($this->somethingElseIsInvalid()) {
            $validator->errors()->add('field', 'Something is wrong with this field!');
        }
    });
}
```
@dmongeau dmongeau merged commit fe388e5 into folkloreinc:develop Feb 1, 2018
@hailwood hailwood deleted the patch-1 branch February 1, 2018 20:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants