Where exactly should a models validity be checked? Is it correct to use a custom Request class or should validation be done from within the model?
For example, if I use a custom form request class and set the rules there, this will validate based on the data submitted by the form. If I then create an eloquent model from that valid data and add some more fields - such as generating a slug from the title in a blog post - the model could then be in an invalid state if that slug isn't unique.
My first thought was to override the eloquent model's save() method and check everything is still valid, but this seems messy since I'd be checking for validity in two places - both the form request and also on model save.
I used to put validations in the controller then it got too "clunky". Then I placed them in the model. But now I put all my validation in custom request classes. For me, it's more organized.
I've done something like this but the way I did it is I have 2 columns. One is a title column and a title_slug column in the db. I validate both columns' uniqueness. So the value you'll be checking against is str_slug($request->title). Not too sure the exact syntax. I'm out waiting for someone and not behind a laptop. Hope you get the idea.