public function asConnection(Model $entity, ?string $database): ?string
    {
        $repository = $this->app->make('config');
        $tenants = $this->getConfig('connection');

        if (! \is_null($tenants)) {
            $database = $tenants['name'];
        }

        if (\substr($database, -5) !== '_{id}' && $this->getConfig('shared', true) === false) {
            $database .= '_{id}';
        }

        $connection = $this->bindWithKey($entity, $database);
        $name = "database.connections.{$connection}";

        if (! \is_null($tenants) && \is_null($repository->get($name))) {
            $config = $this->app->call($tenants['resolver'], [
                'entity' => $entity,
                'template' => $tenants['template'],
                'connection' => $connection,
                'migrator' => $this,
            ]);

            $repository->set($name, $config);
        }

        return $connection;
    }
public function asConnection(Model $entity, ?string $database): ?string
    {
        $repository = $this->app->make('config');
        $tenants = $this->getConfig('connection');

        if (! \is_null($tenants)) {
            $database = $tenants['name'];
        }

        if (\substr($database, -5) !== '_{id}' && $this->getConfig('shared', true) === false) {
            $database .= '_{id}';
        }

        $connection = $this->bindWithKey($entity, $database);
        $name = "database.connections.{$connection}";

        if (! \is_null($tenants) && \is_null($repository->get($name))) {
            $config = $this->app->call($tenants['resolver'], [
                'entity' => $entity,
                'template' => $tenants['template'],
                'connection' => $connection,
                'migrator' => $this,
            ]);

            $repository->set($name, $config);
        }

        return $connection;
    }
public function asConnection ( Model $ entity , ? string $ database ) : ? string { $ repository = $ this -> app -> make ( 'config' ) ; $ tenants = $ this -> getConfig ( 'connection' ) ; if ( ! \ is_null ( $ tenants ) ) { $ database = $ tenants [ 'name' ] ; } if ( \ substr ( $ database , - 5 ) !== '_{id}' && $ this -> getConfig ( 'shared' , true ) === false ) { $ database .= '_{id}' ; } $ connection = $ this -> bindWithKey ( $ entity , $ database ) ; $ name = "database.connections.{$connection}" ; if ( ! \ is_null ( $ tenants ) && \ is_null ( $ repository -> get ( $ name ) ) ) { $ config = $ this -> app -> call ( $ tenants [ 'resolver' ] , [ 'entity' => $ entity , 'template' => $ tenants [ 'template' ] , 'connection' => $ connection , 'migrator' => $ this , ] ) ; $ repository -> set ( $ name , $ config ) ; } return $ connection ; }
Set tenant database connection.

@param  \Illuminate\Database\Eloquent\Model  $entity
@param  string|null  $database

@return string|null
Set tenant database connection .