H
H
hrustbb22020-03-10 19:13:51
Laravel
hrustbb2, 2020-03-10 19:13:51

Is it correct to place the validation logic in the Request class?

The essence of the question is in the title. In numerous examples for Laravel, as a best practice, it is recommended to place the request validation logic in the Request class. Doesn't this violate the Single Responsibility Principle, especially if this logic goes beyond the usual checking of parameters matching some regular expression?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2020-03-10
@hrustbb2

Well, yes, not according to SOLID code :) If you are talking about this
https://github.com/laravel/framework/blob/7.x/src/...
A couple of principles are strongly violated:

  • Single Responsibility Principle
  • Liskov Substitution Principle - you cannot replace FormRequest with the Request class, where there is a link to an interface specific to FormRequest

But, by the way, this is a pretty convenient way to validate :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question