Would it make sense to have a trait to implement Illuminate\Contracts\Validation\DataAwareRule for custom validation rules? #54413
Unanswered
rolfvandekrol
asked this question in
Ideas
Replies: 1 comment 1 reply
-
I might be playing the devil's advocate here, but why did you even implement it as an anonymous class in the first place? 😂 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I found myself implementing a rather complicated request validation where I needed multiple custom validation rules that also needed other data.
So I have several sections in my rules that look a bit like this
I was kinda surprised that Laravel didn't have a trait that i could use to keep the boilerplate of implementing
DataAwareRule
out of my code. In Laravel core there are three rules (File
,Password
andEmail
) that implementDataAwareRule
. Those could also benefit from this trait.Would such a trait would be a helpful addition to the framework? I would like to add it.
If so, a few questions to think about:
Illuminate\Validation\Concerns\HasDataAwareness
Illuminate\Contracts\Validation\ValidatorAwareRule
. Would we also want a helper trait for that? I didn't find myself needing it in my use case, but maybe others do.With this proposed change my code would look like this
Beta Was this translation helpful? Give feedback.
All reactions