Hello! In our previous lesson, you saw how to refactor code to align with the SOLID principles, often using techniques that are second nature in Laravel, like service classes and dependency injection. We established that SOLID principles help us identify problems in our code design. Today, we'll start building a formal vocabulary for the solutions to these problems: Design Patterns.
This lesson is all about mapping the theoretical world of design patterns to the practical reality of the Laravel framework you work with every day. Your goal is to learn the standard classification of these patterns and, most importantly, to recognize how many of them are already implicitly at work in your projects. This will bridge the gap between your implicit, hands-on knowledge and the formal, explicit language of software architecture.
What are Design Patterns?
At its core, a design pattern is a general, reusable solution to a commonly occurring problem within a given context in software design. They are not finished designs that can be transformed directly into code but rather a description or template for how to solve a problem that can be used in many different situations. They are the distilled wisdom of countless developers who came before us.
The following article provides a concise introduction to what design patterns are and why they are so crucial in a modern framework context.
15 Laravel Design Patterns for Peak Performance & Scalability
Please read the introduction of this article by Poovarasu.
Read the first two sections, "What Are Design Patterns?" and "Why Are Design Patterns Important in Laravel?". As you read, notice how the benefits listed—such as reusability, maintainability, and testability—directly correlate with the goals of the SOLID principles we've just covered.
The Three Categories of Design Patterns
The most influential work on this topic is the book Design Patterns: Elements of Reusable Object-Oriented Software, written by four authors often called the "Gang of Four" (GoF). They categorized 23 classic patterns into three main groups based on their purpose.
This short, fast-paced video gives an excellent overview of these categories.
10 Design Patterns Explained in 10 Minutes
Watch the introduction from the "10 Design Patterns Explained in 10 Minutes" video by Fireship.
Watch just the introductory segment from the beginning to the end of the category definitions. This will give you a clear, high-level understanding of the three buckets we'll be using.
To summarize and visualize, the three categories are:
- Creational Patterns: These patterns deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. They increase the flexibility and reuse of existing code.
- Structural Patterns: These patterns concern class and object composition. They explain how to assemble objects and classes into larger structures while keeping these structures flexible and efficient.
- Behavioral Patterns: These patterns are concerned with algorithms and the assignment of responsibilities between objects. They describe patterns of communication between objects.
The following image provides a classic overview of the GoF patterns, sorted into these categories.

Uncovering Patterns Within Laravel
As a senior developer, you know that much of Laravel's power comes from its "magic"—the elegant and expressive ways it solves complex problems. A significant part of that magic is its deep, often invisible, integration of these classic design patterns.
The following presentation from Laracon by Mary Perry is a fantastic tour of how Laravel's core is built upon these patterns. As you watch the selected clips, your goal is to connect the formal pattern name to a feature you already use.
Design Patterns | Mary Perry at Laracon US 2025
Watch the introductory segment of "Design Patterns" by Mary Perry.
Watch from the start of the main talk to understand the philosophy: you don't always need to know the names to get the benefits, but knowing them provides a powerful language for communication and deeper understanding.
Now, let's dive into specific examples from each category.
1. Creational Patterns in Laravel
These patterns provide various object creation mechanisms, which increase flexibility and reuse of existing code.
-
Singleton Pattern: Ensures a class only has one instance and provides a global point of access to it.
- In Laravel: The most fundamental example is the Application/Service Container itself. Whenever you use
app()or resolve a service bound as a singleton, you are using this pattern to ensure you're always working with the same instance (e.g., for config, database connections).
- In Laravel: The most fundamental example is the Application/Service Container itself. Whenever you use
-
Factory Pattern: Creates objects without exposing the instantiation logic to the client and refers to the newly created object using a common interface.
- In Laravel: You use this every time you call
User::factory()->create(). TheUserFactoryclass is responsible for creatingUsermodels. Laravel's session manager is also a factory; it creates the appropriate session driver (file, cookie, database) based on your configuration.
- In Laravel: You use this every time you call
-
Builder Pattern: Separates the construction of a complex object from its representation so that the same construction process can create different representations.
- In Laravel: This is one of the most visible patterns. The Eloquent and Query Builders are perfect examples. Each method call (
->where(),->orderBy(),->join()) contributes to building a complex SQL query object, which is only executed when you call->get()or->first().
- In Laravel: This is one of the most visible patterns. The Eloquent and Query Builders are perfect examples. Each method call (
Let's watch the segments of the Laracon talk that cover these exact patterns.
Design Patterns | Mary Perry at Laracon US 2025
Watch the segments from Mary Perry's talk on Creational patterns in Laravel.
Singleton: Watch the section on the Laravel application as a singleton. Factory: Watch the explanation of factories in the session manager. Builder: Watch how the builder pattern is used for middleware.
2. Structural Patterns in Laravel
These patterns focus on how classes and objects can be composed to form larger, more flexible structures.
-
Facade Pattern: Provides a simplified, static interface to a complex subsystem.
- In Laravel: This is an explicit, famous feature.
Cache::get(),Log::info(),Route::get()are all facades providing a simple, memorable API over more complex services resolved from the container.
- In Laravel: This is an explicit, famous feature.
-
Adapter Pattern: Allows objects with incompatible interfaces to collaborate.
- In Laravel: The entire system of drivers for Cache, Queues, and Filesystems uses this. You can write
Storage::put(...)and Laravel'sStorageManageruses an appropriate adapter to translate that call for AWS S3, local disk, or another driver, all of which have different underlying APIs.
- In Laravel: The entire system of drivers for Cache, Queues, and Filesystems uses this. You can write
-
Repository Pattern: (Not an official GoF pattern, but a very common architectural pattern). Mediates between the domain and data mapping layers using a collection-like interface for accessing domain objects.
- In Laravel: While not built-in, this pattern is extremely popular in large Laravel apps. It involves creating a class (e.g.,
UserRepository) that abstracts away database queries from your controllers or services. This isolates your application's business logic from the specifics of data persistence (e.g., Eloquent).
- In Laravel: While not built-in, this pattern is extremely popular in large Laravel apps. It involves creating a class (e.g.,

Let's see how the Laracon talk explains the Facade pattern.
Design Patterns | Mary Perry at Laracon US 2025
Watch the segment on the Facade pattern.
This clip, from the beginning of the Facade section, explains how facades hide complexity and are a core part of the Laravel experience.
3. Behavioral Patterns in Laravel
These patterns are concerned with the communication between objects and how responsibilities are assigned.
-
Observer Pattern: Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
- In Laravel: Eloquent model observers and the entire Event/Listener system are direct implementations. When you fire
event(new OrderPlaced($order)), any listeners subscribed to that event are automatically executed. This decouples the action (placing an order) from the reactions (sending an email, updating inventory).
- In Laravel: Eloquent model observers and the entire Event/Listener system are direct implementations. When you fire
-
Strategy Pattern: Defines a family of algorithms, encapsulates each one, and makes them interchangeable. This lets the algorithm vary independently from clients that use it.
- In Laravel: This is closely related to the Adapter pattern. The choice of a mail driver (SMTP, Log, Mailgun), cache driver, or session driver is a runtime selection of a "strategy" for handling a specific task. You used this pattern in the last lesson to refactor code violating the Open/Closed Principle.
-
Command Pattern: Encapsulates a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.
- In Laravel: Queued Jobs are a perfect implementation. When you dispatch a job, you are encapsulating a task (like processing a video or sending a report) into an object that can be serialized, queued, and executed later by a worker. Artisan commands (
php artisan ...) also follow this pattern.
- In Laravel: Queued Jobs are a perfect implementation. When you dispatch a job, you are encapsulating a task (like processing a video or sending a report) into an object that can be serialized, queued, and executed later by a worker. Artisan commands (
Now, watch the final set of clips from the talk covering these behavioral patterns.
Design Patterns | Mary Perry at Laracon US 2025
Watch the segments from Mary Perry's talk on Behavioral patterns.
Observer: Watch the section on the Observer pattern with Eloquent models. Strategy: This pattern is explained clearly, covering how different components are decoupled but interchangeable. Watch the segment from the beginning of the Strategy section. Command: See how this is explained in the context of actions and controllers from the start of the Command/Action section.
Conclusion
Today, we've organized the abstract concept of design patterns into a structured framework of creational, structural, and behavioral categories. More importantly, you've seen that these aren't just academic theories; they are the very bedrock of the Laravel framework you've mastered. You have been using Singletons, Factories, Builders, Facades, Observers, and Strategies all along. Now, you have the formal vocabulary to describe them, discuss them, and consciously apply them in your own architectural decisions.
Key Takeaways:
- Design Patterns are categorized into three groups:
- Creational: Concerned with object instantiation (e.g., Factory, Builder, Singleton).
- Structural: Concerned with object composition (e.g., Facade, Adapter, Decorator).
- Behavioral: Concerned with object communication (e.g., Observer, Strategy, Command).
- Modern frameworks like Laravel are built on these patterns, giving you their benefits "for free."
- Knowing the pattern names provides a powerful shared language for discussing software architecture and design choices.
In our next lesson, we will begin a deeper dive into the first category, Creational Design Patterns. You will move from simply identifying patterns to implementing them yourself, starting with the Factory Method to delegate object creation to subclasses.