Singleton: Ensure only one instance of a class exists, and provide a global access point to it. The Singleton pattern ensures a class has only one instance and gives global access to it. A configuration object or a database connection pool are classic examples. It is easy to implement and easy to overuse. A singleton is global state in disguise: any code can reach it and change it, which hides dependencies and makes testing harder, since tests can affect each other through the shared instance.
Modern frameworks offer a better way. In Laravel, you register a class as a singleton in the service container and receive it through dependency injection. You still get one shared instance, but dependencies are explicit and tests can swap in a fake. In long-running setups such as Octane, be careful that singletons do not carry data from one request to the next.
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.