Source: paulund.co.uk

Design Patterns - Singleton
Singleton is a design pattern that lets you ensure that a class only has one instance, while also allowing you to have global access to the single object. Think of a class that needed to connect to a database, this is the perfect situation for a singleton class.

You only ever need one connect to the database and all your queries will be made through this single connection. Having global access to this single object will ensure that a new object (connection) isn't needed to be created and you can reuse the existing object with an already open connection to the database. This is where a singleton pattern will come in allowing you to create a single connection to the database.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners