How to Structure Laravel Projects
October 2022 / 2 h 07 min / Laravel 9
Watch Video About the Course
IMPORTANT NOTICE: Since September 2022, I'm moving from this Teachable platform to my own LaravelDaily.com with this course and even more premium tutorials there. So, please subscribe to yearly/monthly membership there, this Teachable platform will not get new content anymore.
With any questions about the membership, email me [email protected]
The most often question I hear in Laravel is this:
“Where should I put this code logic?”
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?
- Function in the Model?
- Separate class, like Service? Or Action?
- Put as a Job into the Queue?
- Or, maybe, a global helper function without any class?
- And the list goes on.
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.
Notice: this course won’t be about design patterns. So fancy keywords like Singleton, Factory, Adapter etc will be used only when appropriate.
What I will try to do is focus on the practical side: folders, classes and methods, and not on how that pattern actually is called in theory. In reality, every project is actually a mix of patterns, and developers don’t even know how they’re called.
Course Curriculum
-
StartMoving Validation to Form Request Class (4:41)
-
StartTransform Data Before Saving: Mutator or Observer (5:18)
-
StartSaving Data: Service or Action Class? (5:53)
-
StartRepositories: Why NOT to Use Them? (4:16)
-
Start"Background" Tasks: Dispatch Jobs into Queue (3:27)
-
StartDispatch an Event and Let Others Listen to it (5:31)
-
StartRepeating Responses: Base Controller or Trait? (3:41)
-
StartGlobal Helpers: Methods That "Don't Fit" Anywhere Else (2:59)
-
StartEloquent Mutators: 2 Open-Source Examples (3:41)
-
StartService Classes: 2 Open-Source Examples (3:20)
-
StartActions Classes: 2 Open-Source Examples (2:22)
-
StartJobs & Queues: 2 Open-Source Examples (2:37)
-
StartEvents & Listeners: 2 Open-Source Examples (4:02)
-
StartTraits: 2 Open-Source Examples (2:19)
-
StartGlobal Helpers: 2 Open-Source Examples (2:46)
Your Instructor
I consider myself a Laravel expert. Work with Laravel for around 7 years, sharing my thoughts on the YouTube channel "Laravel Daily": https://www.youtube.com/c/LaravelDaily
I also have written a Laravel Daily Blog for 5+ years.