Prototype: Create new objects by copying (cloning) an existing object instead of constructing from scratch. The Prototype pattern creates new objects by copying an existing one, rather than building them from scratch. You keep a prepared example and clone it whenever you need another, then adjust what is different. This helps when creating an object is expensive or involves many settings. A document template with default styles, a game unit with standard stats or a preconfigured report definition can all serve as prototypes.
In PHP, you use clone, and the __clone() method lets you decide how nested objects are copied. Make sure deep copies are made where needed, or the clones will share data with the original and with each other. In many cases, a factory method or a builder with sensible defaults achieves the same result in a way that is easier to read.
Apply Spatie's Laravel and PHP coding standards for any task that creates, edits, reviews, refactors, or formats Laravel/PHP code or Blade templates; use for controllers, Eloquent models, routes, config, validation, migrations, tests, and related files to align with Laravel conventions and PSR-12.
Implement proven backend architecture patterns including Clean Architecture, Hexagonal Architecture, and Domain-Driven Design. Use this skill when designing clean architecture for a new microservice, when refactoring a monolith to use bounded contexts, when implementing hexagonal or onion architecture patterns, or when debugging dependency cycles between application layers.