Skip to content

Commit 2f1578b

Browse files
authored
Update ClickHouseServiceProvider.php
1 parent c4e7537 commit 2f1578b

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/ClickHouseServiceProvider.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,23 @@
1111

1212
class ClickHouseServiceProvider extends ServiceProvider
1313
{
14+
/**
15+
* @return void
16+
*/
1417
public function boot(): void
1518
{
16-
/** @var DatabaseManager $db */
17-
$db = $this->app->get('db');
19+
$this->app->resolving('db', function ($db) {
20+
$db->extend('clickhouse-ext', function ($config, $name) {
21+
$config['name'] = $name;
22+
$connection = new Connection($config);
23+
if ($this->app->bound('events')) {
24+
$connection->setEventDispatcher($this->app['events']);
25+
}
1826

19-
$db->extend('clickhouse-ext', function ($config, $name) {
20-
$config['name'] = $name;
21-
$connection = new Connection($config);
22-
if ($this->app->bound('events')) {
23-
$connection->setEventDispatcher($this->app['events']);
24-
}
27+
return $connection;
28+
});
2529

26-
return $connection;
30+
Model::setConnectionResolver($db);
2731
});
28-
29-
Model::setConnectionResolver($db);
3032
}
3133
}

0 commit comments

Comments
 (0)