1

I use DB facade. I see it can use in DB::connection from Illuminate\Database\DatabaseManager and DB::select from Illuminate\Database\Connection.

enter image description here

I don't understand how one facade can apply two serivce?

Thank you for your asking!

ray
  • 241
  • 2
  • 13

1 Answers1

1

One Facade can point to multiple classes for different methods. This is possible through the magic method __call.

Here's the __call method of the DatabaseManager class:

 /**
 * 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);
}

The DB facade points to the DatabaseManager class and if the method is not found the DatabaseManager then forwards the call to the Connection class.

Paras
  • 9,258
  • 31
  • 55