Skip to content

Commit

Permalink
Add support for adding connections after boot (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
jholloman authored Oct 18, 2024
1 parent c328c8f commit 4ac2790
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/SqlCommenterServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ public function packageBooted(): void
$connections = [config('database.default')];
}

collect($connections)->each(fn (string $conn) => DB::connection($conn)->beforeExecuting(function (
collect($connections)->each(fn (string $conn) => $this->initiateForConnection($conn));
}

public function initiateForConnection(string $conn): void
{
DB::connection($conn)->beforeExecuting(function (
string &$query,
array &$bindings,
Connection $connection,
Expand All @@ -47,7 +52,7 @@ public function packageBooted(): void
$commenters = $this->instanciateCommenters(config('sql-commenter.commenters'));

$query = $sqlCommenter->commentQuery($query, $connection, $commenters);
}));
});
}

/**
Expand Down

0 comments on commit 4ac2790

Please sign in to comment.