What is the Facade pattern in PHP/Laravel?
Why Interviewers Ask This
This tests whether you can apply PHP knowledge to real-world scenarios. Interviewers are looking for clarity of thought and evidence that you've encountered this in production code.
Answer
The Facade pattern provides a simplified, static-like interface to complex subsystems. In Laravel, facades are proxy classes that forward static method calls to underlying objects resolved from the service container. Example: Cache::get("key") appears to be a static call but actually resolves the CacheManager from the container and calls get() on it. Each facade defines a getFacadeAccessor() method returning the container binding key. Benefits: concise, readable syntax without dependency injection boilerplate for common operations. Drawbacks: can make dependencies implicit (harder to see what a class depends on) and can make unit testing harder (use Cache::shouldReceive() in tests). Real facades differ from static methods — the underlying object is injected and testable.
Pro Tip
This topic has PHP-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.
Previous
What is the Adapter pattern in PHP?
Next
What is the difference between method chaining and fluent interface?