Answer the question
In order to leave comments, you need to log in
Why are FormRequests needed in Laravel 5?
Hi all! I don't understand why FormRequests are needed in Laravel 5, i.e. Isn't it easier to hang a validator on a model than to follow requests?
Answer the question
In order to leave comments, you need to log in
The model should not be able to enter an invalid state. Never. That is, all the data that you send to the model must already be validated, and inside the model, inside some methods, the business rules are already checked directly.
FormRequest in Laravel is none other than DTO, and this is cool because it allows you to completely decouple the logic of the data representation (request is also a data representation, whatever one may say) from the business logic. Business logic should not know anything about any forms there and how the user interacts with your application.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question