Laravel Services Muzaffargarh
This applies to software development as well. Understanding which portion of the code goes where is the key to a maintainable code base.
Laravel being an elegant web framework, comes with a pretty organized directory structure by default but still I've seen a lot of people suffer.
Don't get me wrong. It's a no brainer that controllers go inside the controllers
directory, no confusions whatsoever. The thing people often confuse themselves with is, what to write in a controller and what not to.
Table of Content
- Project Codes
- The Scenario
- Understanding Business Logic
- Service Classes to the Rescue
- Action Re-usability
- Closing Thoughts
When to use this?
Usually, when you would easily replace that with a simple function, without class. It’s like a global helper, but sitting inside of ReportService class just for the sake of staying with object-oriented code, and to keep order – with namespaces and folders.
Also, keep in mind that static methods and classes are stateless. It means that the method is called only for that one time, and doesn’t save any data within that class itself.
But if you do want to keep some data inside that service…
No comments:
Post a Comment