dwightwatson / validating

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

Custom validation rule in the model #214

Closed snuzi closed 5 years ago

snuzi commented 5 years ago

Hi there, I found this library very useful, but I am finding it very difficult to set some custom rules in the model. Ex: I have an attribute keywords which should store some keywords comma separated "word1,word2". I want to have make a function to perform a custom rule for keywords attribute. I could find a workaround to put the custom validation rule in the controller (rest API response) like: $request-> validate(['keywords' => new MyValidation()])

I would appreciate if this library supports that case, or if anyone managed to make it work in the model. Thanks

dwightwatson commented 5 years ago

I think this is the same issue as #177 - where this library validates content through accessors/mutators rather than the request input or raw database data. This is unlikely to change any time soon I'm afraid, but discussion can continue in the other issue.