Skip to content

Commit

Permalink
Merge pull request #11 from crlcu/master
Browse files Browse the repository at this point in the history
Debugbar output
  • Loading branch information
mpociot committed Jul 18, 2018
2 parents b9a329a + 3633926 commit d3763f5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config/config.php
Expand Up @@ -29,6 +29,10 @@
* Displays an alert on the website
* \BeyondCode\QueryDetector\Outputs\Alert::class
*
* Debugbar: (make sure you have the barryvdh/laravel-debugbar package installed)
* Writes the N+1 queries into a custom messages collector of Debugbar
* \BeyondCode\QueryDetector\Outputs\Debugbar::class
*
* Log:
* Writes the N+1 queries into the Laravel.log file
* \BeyondCode\QueryDetector\Outputs\Log::class
Expand Down
27 changes: 27 additions & 0 deletions src/Outputs/Debugbar.php
@@ -0,0 +1,27 @@
<?php

namespace BeyondCode\QueryDetector\Outputs;

use Illuminate\Support\Collection;
use Symfony\Component\HttpFoundation\Response;

use Debugbar as LaravelDebugbar;
use DebugBar\DataCollector\MessagesCollector;

class Debugbar implements Output
{
public function output(Collection $detectedQueries, Response $response)
{
$collector = new MessagesCollector('N+1 Queries');

foreach ($detectedQueries as $detectedQuery) {
$collector->addMessage(sprintf('Model: %s => Relation: %s - You should add with(%s) to eager-load this relation.',
$detectedQuery['model'],
$detectedQuery['relation'],
$detectedQuery['relation']
));
}

LaravelDebugbar::addCollector($collector);
}
}

0 comments on commit d3763f5

Please sign in to comment.