Laravel 4 loading class and facades
I want to know how Laravel loads a class via Facades.
I came across this answer which said the DB
alias / facade class loaded the code
here /vendor/laravel/framework/src/Illuminate/Database/Connection.php
I tried following the guidelines in the answer and following what the code from index.php does, but couldn't figure out how DB
Facade loaded the class Connection
.
I am a little more confused because the answer said the class is Connection
loaded, but this class has no method Connection
. However, the documentation says and I was able to use a connection method like
DB::connection('my-connection-name');
here's the docs link for that
I want to know where this is all mapped and how the download is happening. I'm assuming composer has automated the mapping, but where does this happen when my app loads?
source to share
When you use a static database call, Laravel uses the mechanism provided by the Facade class in Illuminate \ Support \ Facade . The magic method __callStatic is called and gets the "original" class, which is provided to the database service provider .
Oh, and you can use DB and not Illuminate \ Support \ Facades \ DB because an alias is created in the application config file.
Hope this helps you :)
source to share