-
Notifications
You must be signed in to change notification settings - Fork 11.5k
[12.x] Add HasValidation Trait #55986
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
[12.x] Add HasValidation Trait #55986
Conversation
Nice! A follow-up would be to define auto-triggers for validation (e.g. validate on save) |
If this one gets approved, that can be a nice follow-up indeed!!! 💪 |
One step closer to making Request objects classes with typed properties 💪 |
While I understood the purpose of this, now that I understand a little of Taylor's vision, I would say that this is a type of feature that you should create into your project or offer as a package. |
I fully expect Taylor to close this but that does not mean that I wouldn't love having this feature in Laravel |
Yeah @devajmeireles @shaedrich I don't mind having PRs closed, I already contributed some that were merged and some others that were closed. |
You're absolutely right. I would also say that it brings us benefits, I can see the benefits of it, but, as I said, I see it more as a question of project design. |
Exactly! I would like to have this built-in the framework because I think it can help, but let's see what Taylor and the team will decide. |
I personally feel this is simple enough to implement in user-land I would prefer to leave it as a package. 👍 |
Got it,thanks! 💪 |
Changes
This PR adds a new trait:
HasValidation
. This was heavily inspired (and most of its implementation is based also) in my Validated DTO package. The trait is an abstraction around theValidator
facade, making it easier to create any types of classes with a built-in validation system.Why to have this Trait
The
Validator
facade already helps a lot on creating validations for any classes we want, this is just a small improvement on DX that will abstract the "boilerplate" code.With this, any classes (even Models) can define their validations by simply using the Trait and defining a
rules
method. But it also gives control for setting custom messages with themessages
method, setting custom attributes with theattributes
method and it also supports theafter
validation of theValidator
.Example
More examples can be found in the Test file in this PR.