My problem:
Right now complex validation that cannot be handled through rules (e.g. $validator->sometimes(...) or $validator->after(...)) is hard to implement in imports, because there is no way to configure the validator that is being used. This causes a rift between FormRequest and Import validation (and honestly creates code depth in the import due to extra ifs and manual failures)
My proposal:
I propose to add the ability to configure the validator through a withValidator method, similar to how this is possible in a FormRequest.
Similar to FormRequest this method would be optional, so that it would only have to be implemented when its needed. The RowValidator class can check for method existence when it's creating the validator instance for an import.
class UserImport implements WithValidation
{
public function withValidator(Validator $validator)
{
$validator->after(function ($validator) {
if ($this->somethingElseIsInvalid()) {
$validator->errors()->add(...);
}
});
}
}
Hey @axlon I'm fine with your proposal, feel free to PR!
PR is merged. Will be included in next release. Thanks again for the great PR!
Released
Most helpful comment
Hey @axlon I'm fine with your proposal, feel free to PR!