Skip to content

Commit 612b7e4

Browse files
authored
Merge pull request #25 from marcmascort/master
Add Json ouput for APIs
2 parents be3f050 + 2306de8 commit 612b7e4

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ return [
9595
If you use **Lumen**, you need to copy the config file manually and register the Lumen Service Provider in `bootstrap/app.php` file
9696

9797
```php
98-
$this->app->register(\BeyondCode\QueryDetector\LumenQueryDetectorServiceProvider::class);
98+
$app->register(\BeyondCode\QueryDetector\LumenQueryDetectorServiceProvider::class);
9999
```
100100

101101
If you need additional logic to run when the package detects unoptimized queries, you can listen to the `\BeyondCode\QueryDetector\Events\QueryDetected` event and write a listener to run your own handler. (e.g. send warning to Sentry/Bugsnag, send Slack notification, etc.)

src/Outputs/Json.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
namespace BeyondCode\QueryDetector\Outputs;
3+
4+
use Illuminate\Support\Collection;
5+
use Symfony\Component\HttpFoundation\Response;
6+
use Illuminate\Http\JsonResponse;
7+
8+
class Json implements Output
9+
{
10+
11+
public function output(Collection $detectedQueries, Response $response)
12+
{
13+
if ($response instanceof JsonResponse) {
14+
$data = $response->getData(true);
15+
$data['warning_queries'] = $detectedQueries;
16+
$response->setData($data);
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)