Illuminate\Database\Eloquent\Model::setConnectionResolver PHP Method

setConnectionResolver() public static method

Set the connection resolver instance.
public static setConnectionResolver ( Illuminate\Database\ConnectionResolverInterface $resolver ) : void
$resolver Illuminate\Database\ConnectionResolverInterface
return void
    public static function setConnectionResolver(Resolver $resolver)
    {
        static::$resolver = $resolver;
    }

Usage Example

Example #1
2
 /**
  * Initialize the Laravel framework.
  * @param SymfonyRequest $request
  */
 private function initialize($request = null)
 {
     // Store a reference to the database object
     // so the database connection can be reused during tests
     $oldDb = null;
     if ($this->app['db'] && $this->app['db']->connection()) {
         $oldDb = $this->app['db'];
     }
     // The module can login a user with the $I->amLoggedAs() method,
     // but this is not persisted between requests. Store a reference
     // to the logged in user to simulate this.
     $loggedInUser = null;
     if ($this->app['auth'] && $this->app['auth']->check()) {
         $loggedInUser = $this->app['auth']->user();
     }
     // Load the application object
     $this->app = $this->kernel = $this->loadApplication();
     // Set the request instance for the application
     if (is_null($request)) {
         $appConfig = (require $this->module->config['project_dir'] . 'config/app.php');
         $request = SymfonyRequest::create($appConfig['url']);
     }
     $this->app->instance('request', Request::createFromBase($request));
     $this->app->instance('middleware.disable', $this->module->config['disable_middleware']);
     // Bootstrap the application
     $this->app->make('Illuminate\\Contracts\\Http\\Kernel')->bootstrap();
     // Restore the old database object if available
     if ($oldDb) {
         $this->app['db'] = $oldDb;
         Model::setConnectionResolver($this->app['db']);
     }
     // If there was a user logged in restore this user.
     // Also reload the user object from the user provider to prevent stale user data.
     if ($loggedInUser) {
         $refreshed = $this->app['auth']->getProvider()->retrieveById($loggedInUser->getAuthIdentifier());
         $this->app['auth']->setUser($refreshed ?: $loggedInUser);
     }
     $this->module->setApplication($this->app);
 }
All Usage Examples Of Illuminate\Database\Eloquent\Model::setConnectionResolver
Model