0

There must be a good reason for this. Laravel's default pattern makes no use of Service Classes... but the Laravel community's best practices is for business logic to be stored in them.

Laravel's default pattern seems to break SRP, and there's no Artisan command for creating a service class, or even any reference to using them in Laravel's documentation.

This is obviously a very conscious decision by Taylor Otwell. So why did he do it? There must be a clear reason. Does Laravel not concern itself with SOLID?

2
  • I would imagine that it is a limitation of real life and not having infinite time and space, so ideally they would but the fact is that nobody has gotten around to fixing it because there is more important things to do.
    – r_ahlskog
    Jul 14, 2021 at 8:11
  • Depends heavily on your interpretation of SRP, which has almost as many interpretations as there are developers trying to follow it. It would help if you described (with code examples) what specifically you think violates SRP and why. Jul 14, 2021 at 11:36

1 Answer 1

1

Laravel is an implementation of the Model-View-Controller design pattern. The MVC design pattern does not include the idea of a "service class". Business logic and data access is crammed into the "Model" part of MVC. This part of the design pattern is loosely defined. The most important thing to remember with MVC is that it is a user interface design pattern, not an all-inclusive architecture. How to organize business logic and data access logic is outside the scope of the MVC design pattern, and therefore outside the scope of the Laravel framework.

The Laravel community might be leaning towards service classes for organizing business logic, but that is subjective and depends on the complexity of logic, among many other things. Other design patterns and techniques like Clean Architecture, Onion Architecture and Domain Driven Design focus on the bigger picture of how code is organized and architected, and this may include utilizing MVC for the user interface portion of the application.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.