Replies: 2 comments
-
@h-sigma First of all, thank you for your consideration for new features. New ideas and feature discussions are always welcome. I'm having a bit of a hard time following where this would be beneficial? Is there a specific problem you are trying to solve here? If you are trying to keep code cleaner and more "Laravel" like, there is also a request macro to better integrate with requests: https://github.com/surgiie/transformer#use-the-request-macro which might be a cleaner approach for you. Im not sure Im in favor of the feature as this would essentially be responsible for something the Laravel framework already handles for us. Things start to get more complicated with closures since the validation components also use closures to do validation. $this->validateAndTransform(['first_name'=>' Bob'], ['required', function ($value) {
// how do we know this is a validation or transformation closure?
return $value;
}] ); You mentioned a special character, such as |
Beta Was this translation helpful? Give feedback.
-
Combining the two into one makes some sense to me, as I'd consider request validation and formatting of input as subsequent steps in the request handling flow, but I can see how this is an arbitrary preference. This might be something that's better added to my own project as a helper, instead of bogging down this package. Thanks for considering my suggestion 👍 |
Beta Was this translation helpful? Give feedback.
-
First of all, like the package. It's something I've been looking for for a while: a transformer package with syntax that aligns with validation rules. Just to make things as Laravel-ey/declarative as possible, I suppose.
What do you think about adding a feature that lets you validate and transform using the same set of properties? Something like:
The main problem to solve would be detecting which properties are meant for validation and which ones for transform. Once that's done, it should be a matter of separating them into their own method calls (one for validation followed by one for transformation). Can even throw an
AmbiguousParameterException
or something along those lines if a name exists for both validation and transformation.Maybe a special symbol/rule in the pattern would be helpful:
The
=>
in the above pattern separates the validations from the transformations (in this example, the validations always come first and then the transformations).@surgiie
Beta Was this translation helpful? Give feedback.
All reactions