feat: allow complex validation rules #91
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I didn't find a way to annotate a complex validation rule and implemented a way for the src/Concerns/RulesValidation.php class to look for an internal Model method that returns an Illuminate\Validation\Rule.
I also modified the applyValidations method call in src/Lift.php to simplify the validation process without needing to be triggered twice.
Example
Solution
Changes
src/Lift.php
I modified the call to the apply Validations method by adding the payment Model $model;
I removed the calls to the methods: applyCreateValidations and applyUpdateValidations;
src/Concerns/RulesValidation.php
I added the parseValidationRules method that checks if a validation rule is a valid method name of the Model and then triggers it.
I changed the signature of the applyValidations method to receive the Model instance.
I merged the validation rules to unite: validationRules, createValidationRules and updateValidationRules according to the Model context.
That's it folks.