Replies: 4 comments 5 replies
-
@goldmont You could use the |
Beta Was this translation helpful? Give feedback.
-
Sure, I know that too but I prefer to not split the rules. I think that's clearer to have all of them in the same place. What do you think about? |
Beta Was this translation helpful? Give feedback.
-
Think about |
Beta Was this translation helpful? Give feedback.
-
@bennothommo would that fit in your PR to add Laravel style relations? |
Beta Was this translation helpful? Give feedback.
-
Hi,
In certain situations Validator rules needs to be computed dynamically. As of now, I have to declare the
$rules
property as an empty array and then, in the model constructor, I have to update its value with my desired rules.E.g.
I use to check if a certain value is compatible with the enum
MyEnum
. In order to do so, I have to create an array of cases on the fly. However, PHP doesn't allow you to do that outside of a function.It would be nice to have a
rules(): array
function that allows us to simply return an array of rules dynamically computed. Just like Laravel does here.Then, this condition inside Validation trait will be:
Also,
$rules
property andrules()
function must be mutually exclusive.Beta Was this translation helpful? Give feedback.
All reactions