How Laravel Facades Route Cache::get() Calls Through the Service Container

Laravel's Cache::get() does not exist on the imported facade class; instead, the Facade base class uses PHP's __callStatic() to forward the call. The facade resolves a service container binding, here a CacheManager, and caches that lookup after the first request. The manager's own magic method then forwards the call to the default store named in configuration. Facades only work once the kernel's RegisterFacades bootstrapper has set the application, which is why calling them from a bare test throws an error. Real-time facades generate facade classes on demand through an autoloader, letting code call non-facade classes statically.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in