DEV Community

Arunas Skirius
Arunas Skirius

Posted on

2 1

How to use Laravel Facades safely

It's not exactly clear in the Laravel documentation, but there's one thing the Facades do that might introduce accidental bugs in your system:

Facades are like singletons.

Unlike traditional service container bindings with anonymous functions, Facades retain the resolved instance and use that in future Facade calls.

In this article I explain why this is happening, and offer a couple solutions to prevent this bug in your code.

Let me know what you think!

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more