in laravel to access query,we use DB facades
DB::select()
from alanstorm website http://alanstorm.com/binding_objects_as_laravel_services i learn that DB facade use callstatic method that lead to DB::app['db']->select().
app is laravel service container object which all the services binded into it. i use vardump php method var_dump(app['db'])
and i see the service container returns an Illuminate\Database\DatabaseManager object. from DatabaseManager class that implement ConnectionResolverInterface i dont see the select method defined there. i want to ask how app['db'] can get access to select method. thanks before
DatabaseManager
class implements __call()
method if you call a method on that class that doesn't exist it's immediately passed as an argument to __call()
, which is one of php's magic methods.
that calls connection class with the method you passed.
here's the method implementation in Illuminate\Database\DatabaseManager
/**
* Dynamically pass methods to the default connection.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)
{
return $this->connection()->$method(...$parameters);
}