11 months ago

Where to locate validation rules and rules based on HTTP verbs

Posted 11 months ago by Veleous

Couple of questions:

What is the convention (if there is one) for locating input validation rules?

Currently I have a function on my eloquent model (which I call from where-ever) that returns an array of validation rules. This feels acceptable to me as it keeps the validation reusable in one place and that my model encapsulates its own validation rules, however, this leads into my next question.

How do people cater for rules based on the request HTTP verb?

Rules for creating a model may differ from those for updating. All fields might be required during a POST, but I might want to allow partial updates via PATCH.

I read this discussion which seems reasonable, but I am not thrilled at the prospect of leading request data into my model (i.e. having to pass the verb as a parameter to my models rules function).

Please sign in or create an account to participate in this conversation.