Skip to content

Commit 5f73905

Browse files
committed
Fixed error when database name set progmatically from application.
1 parent 9dabe4a commit 5f73905

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

55
This project adheres to Semantic Versioning.
66

7+
## 1.1.3 - 2021-06-27
8+
9+
- Fixed error when the database name set dynamically by the application.
10+
711
## 1.1.2 - 2020-11-30
812

913
- Change default host from 0.0.0.0 to 127.0.0.1 because in windows can't use 0.0.0.0.

src/DatabaseWatcher.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function recordQuery(QueryExecuted $event)
5252
$data = [
5353
'url' => Request::url(),
5454
'connection' => $event->connectionName,
55+
'database' => config('database.connections.' . $event->connectionName . '.database'),
5556
'bindings' => $event->bindings,
5657
'sql' => strtolower($this->replaceBindings($event)),
5758
'time' => number_format($event->time, 2, '.', ''),

src/TailDatabaseCommand.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Muhdfaiz\LaravelTailDb;
44

55
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\Config;
67
use Illuminate\Support\Facades\DB;
78
use React\EventLoop\Factory;
89
use React\Socket\ConnectionInterface;
@@ -161,6 +162,11 @@ protected function parseQueryData(string $logData)
161162
protected function executeExplainQuery(array $logData)
162163
{
163164
$explainQuery = 'explain ' . str_replace('Query: ', '', $logData['sql']);
165+
166+
$connection = $logData['connection'];
167+
$key = 'database.connections.' . $connection . '.database';
168+
169+
Config::set($key, $logData['database']);
164170
return DB::connection($logData['connection'])->select($explainQuery);
165171
}
166172

0 commit comments

Comments
 (0)