Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Surviving with thin controllers and models

990 views

Published on

This is a tutorial detailing how to survive with thin controllers and models. Techniques required to make your Laravel controller smaller and lean.

Published in: Software

Surviving with thin controllers and models

  1. 1. Surviving with “Thin” Controllers and Models By Lawrence Enehizena @enoma_lawrence
  2. 2. Introduction Laravel is an MVC based PHP Framework (we all love)
  3. 3. The Laravel “goodness” - Best practices and sanity in teams - Clean and expressive - Amazing community and ecosystem - Productive
  4. 4. Why “Thin” Controller and “Thin” Model ?
  5. 5. Laravel as an “MVC” based Framework
  6. 6. Where do we keep business logic? most times, we are forced to think the MVC way.
  7. 7. Bloats in Controller and Model - Code Complexity - Code Duplication (breaking DRY principle) - Code changes becomes difficult - Scary unit test (Bloated unit test)
  8. 8. So, Again, why : “Thin” The Controller and The Model ? TO REMOVE THE BLOAT!
  9. 9. How do we, “thin” then ?
  10. 10. What is service object? A place for business logic that coordinates interaction in the application
  11. 11. Any downside to “thinning” ?
  12. 12. Lets get into some code
  13. 13. Bloat in “ChargeController” Handles HTTP POST - Creates a new charge
  14. 14. Or in “Charge” model
  15. 15. Lets “thin” both with service object
  16. 16. Folder Structure {where to keep your services}
  17. 17. A “CreateCharge” service object
  18. 18. The “thinned” ChargeController
  19. 19. The “thinned” Charge model
  20. 20. That’s it folks!!

×