dwightwatson / validating

Automatically validating Eloquent models for Laravel
MIT License
968 stars 76 forks source link

How to support different validations rules e.g. on update? #217

Closed bastiankoetsier closed 4 years ago

bastiankoetsier commented 4 years ago

Hey,

thank you very much for your work! I noticed that "some time ago" you offered the possibility to define different rulesets for different events. Any reason why this was removed? How can I now support this use case? I would like to have the validation rules still on the model to not be bound to HTTP/FormRequests.

Again, thank you very much in advance!

Greetings from Berlin

dwightwatson commented 4 years ago

From memory it just became incredibly complex to maintain, especially with all the different use-cases that people wanted. Some event rules would be merged into others (like the created event rules would also inherit the saving event rules) and we had to support custom events as well. It also started to lead to having really large and complex arrays of rules on models that made it hard to work out what was actually happening.

I think when Laravel 5.x shipped with FormRequests it was decided to simplify the package dramatically which lead to a single set of rules.

There may be ways around this if you really want to go down that path but it basically amounts to listing for events and setting the ruleset you want prior to validation.

My honest recommendation would be to adopt Laravel's FormRequest as I think that's more future-proof for your app. If you really want to do model validation, check out the link above, consider forking the 0.10.x branch of this package to get it working on Laravel 6.0, or find another package that better matches your needs.

Hope this is at least a little bit helpful - I know it's probably not the answer you were after.