Pixelairport's avatar

How to valdiate the right way?

I used to use Cartalyst Platform (Laravel Components), which has a validation trait used in the repositories. Now i switched to laravel and read that I dont should use validation in repositories. I also have to find another way to validate forms and user inputs. I did a FormRequest file and load it as closure in my controller. But I dont like that it throws the error. I want to handle the error by my own. If I have errors I want to redirect the user or maybe track the times he did mistakes. So I think about to create a service, that I have the controller (gets the request), which calls the service (which checks the request), which calls the repository (which does database stuff when rest is ok). Is that the right way for me? When I understand all right, I cant use this Form Requests. I just create the Service File, which has a function (e.g. "CreatePost"), which checks everything. Is that right?

0 likes
1 reply

Please or to participate in this conversation.