File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 2929 * Displays an alert on the website
3030 * \BeyondCode\QueryDetector\Outputs\Alert::class
3131 *
32+ * Debugbar: (make sure you have the barryvdh/laravel-debugbar package installed)
33+ * Writes the N+1 queries into a custom messages collector of Debugbar
34+ * \BeyondCode\QueryDetector\Outputs\Debugbar::class
35+ *
3236 * Log:
3337 * Writes the N+1 queries into the Laravel.log file
3438 * \BeyondCode\QueryDetector\Outputs\Log::class
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace BeyondCode \QueryDetector \Outputs ;
4+
5+ use Illuminate \Support \Collection ;
6+ use Symfony \Component \HttpFoundation \Response ;
7+
8+ use Debugbar as LaravelDebugbar ;
9+ use DebugBar \DataCollector \MessagesCollector ;
10+
11+ class Debugbar implements Output
12+ {
13+ public function output (Collection $ detectedQueries , Response $ response )
14+ {
15+ $ collector = new MessagesCollector ('N+1 Queries ' );
16+
17+ foreach ($ detectedQueries as $ detectedQuery ) {
18+ $ collector ->addMessage (sprintf ('Model: %s => Relation: %s - You should add with(%s) to eager-load this relation. ' ,
19+ $ detectedQuery ['model ' ],
20+ $ detectedQuery ['relation ' ],
21+ $ detectedQuery ['relation ' ]
22+ ));
23+ }
24+
25+ LaravelDebugbar::addCollector ($ collector );
26+ }
27+ }
You can’t perform that action at this time.
0 commit comments