When and Why You Should Use Facades in Laravel
Laravel facades provide a simple, expressive way to access services from the service container. This article explains when facades should be used, why they exist, and how they help keep Laravel code clean and readable.
What Is a Facade?
In Laravel, a facade is a simple, static-style way to access services from the service container.
Cache::get('settings');
Log::info('User logged in');
Why Facades Exist
Facades remove boilerplate code and make common operations:
- Easier to read
- Faster to write
- Consistent across the project
They focus on developer experience.
When to Use Facades
Use facades when:
- Calling common framework services
- Writing controller or job logic
- You want readable, expressive code
- The logic is simple and obvious
When to Avoid Facades
Avoid facades when:
- Writing core business rules
- Building reusable packages
- You need explicit dependency control