Skip to content

Commit 8ecd743

Browse files
authored
Merge pull request #8 from Braunson/master
Support for multiple outputs
2 parents a6c71b1 + 03ea4a1 commit 8ecd743

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
The Laravel N+1 query detector helps you to increase your application's performance by reducing the number of queries it executes. This package monitors your queries in real-time, while you develop your application and notify you when you should add eager loading (N+1 queries).
99

10-
![Example alert](https://beyondco.de/github/n+1/alert.png)
10+
![Example alert](https://beyondco.de/github/n+1/alert.png)
1111

1212
## Installation
1313

@@ -42,7 +42,7 @@ return [
4242
* If this is set to "null", the app.debug config value will be used.
4343
*/
4444
'enabled' => env('QUERY_DETECTOR_ENABLED', null),
45-
45+
4646
/*
4747
* Threshold level for the N+1 query detection. If a relation query will be
4848
* executed more then this amount, the detector will notify you about it.
@@ -64,7 +64,7 @@ return [
6464
],
6565

6666
/*
67-
* Define the output format that you want to use.
67+
* Define the output format that you want to use. Multiple classes are supported
6868
* Available options are:
6969
*
7070
* Alert:
@@ -75,7 +75,9 @@ return [
7575
* Writes the N+1 queries into the Laravel.log file
7676
* \BeyondCode\QueryDetector\Outputs\Log::class
7777
*/
78-
'output' => \BeyondCode\QueryDetector\Outputs\Alert::class,
78+
'output' => [
79+
\BeyondCode\QueryDetector\Outputs\Alert::class
80+
]
7981

8082
];
8183
```

config/config.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
],
2323

2424
/*
25-
* Define the output format that you want to use.
25+
* Define the output formats that you want to use.
2626
* Available options are:
2727
*
2828
* Alert:
@@ -33,6 +33,8 @@
3333
* Writes the N+1 queries into the Laravel.log file
3434
* \BeyondCode\QueryDetector\Outputs\Log::class
3535
*/
36-
'output' => \BeyondCode\QueryDetector\Outputs\Alert::class,
37-
38-
];
36+
'output' => [
37+
\BeyondCode\QueryDetector\Outputs\Log::class,
38+
\BeyondCode\QueryDetector\Outputs\Alert::class,
39+
]
40+
];

src/QueryDetector.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,15 @@ public function getDetectedQueries(): Collection
172172

173173
protected function applyOutput(Response $response)
174174
{
175-
$outputType = app(config('querydetector.output'));
176-
$outputType->output($this->getDetectedQueries(), $response);
175+
$outputTypes = app(config('querydetector.output'));
176+
177+
if (! is_array($outputTypes)) {
178+
$types = [$outputTypes];
179+
}
180+
181+
foreach ($outputTypes as $type) {
182+
$type->output($this->getDetectedQueries(), $response);
183+
}
177184
}
178185

179186
public function output($request, $response)

0 commit comments

Comments
 (0)