Where to put your logic?
The most often question I hear in Laravel is this:
“Where should I put this code logic?”
Here’s a typical post from StackOverflow:
Basic Laravel is an MVC framework, it’s clear what should be in Model, View and Controller. But what if you have custom logic for processing data before passing it to the view? Where should it be?
- In the same Controller method?
- Separate private Controller method?
- Static function in Model?
- Separate class, like Service?
- Or, maybe, global helper function without any class?
- Also, I’ve heard Repository is a widely-used pattern?
Of course, the correct answer is it depends. But depends on what?
This is what I’m gonna talk about in this course.
The goal is to discuss practical examples of structuring larger Laravel applications, various approaches and patterns. We will analyze existing popular open-source projects and their structure.