Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Question 10 of 10 · Laravel Framework Fundamentals
Interview question

What are Laravel Facades and how do they work internally? Laravel Facades क्या हैं और internally कैसे काम करते हैं?

Answer

Facades provide a static-looking interface to classes registered in the service container, giving expressive syntax without sacrificing testability.

// Using a facade
Cache::put('key', 'value', 600);

// What happens internally:
// 1. Cache::put() is intercepted by __callStatic()
// 2. Facade resolves the underlying 'cache' binding from the container
// 3. put() is called on that resolved instance
Behind the scenes:
Facade class → getFacadeAccessor() returns binding key → Service container resolves the real object → Method call is forwarded to it
AspectDetail
Not truly staticUnderlying class is a normal object resolved from container
TestableCan be mocked via Cache::shouldReceive()

Facades service container में registered classes के लिए static जैसा interface देते हैं, testability खोए बिना expressive syntax देते हैं।

Cache::put('key', 'value', 600);

// Internally:
// 1. __callStatic() intercept करता है
// 2. Facade container से असली binding resolve करता है
// 3. put() उस resolved instance पर call होता है

Was this answer clear?