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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners