Wooden Wooden - 2 months ago 31
PHP Question

Why laravel define validation in controller instead of Eloquent model?

I am reading the laravel documentation, and there is some doubt about validation

If the web server will provide web interface to desktop user, and api interface to mobile user, there is a problem: It will define validation twice in api controller and web controller, it is duplication.

and if there is a another co-developer to develop a large project, He should to know previous developer defined validation, it is not good for collaborative development

I think It should define validation logic in same place, Like ActiveRecord in Rails


You can create a Request file in the Requests folder and inject this file in controller method and it will automatically validate the request. Please continue reading the Laravel validation documentation here and you will find this method elaborately.