diff --git a/config/config.php b/config/config.php index 03f5ec7..84f1765 100644 --- a/config/config.php +++ b/config/config.php @@ -9,7 +9,7 @@ /* * Threshold level for the N+1 query detection. If a relation query will be - * executed more then this amount, the detector will notify you about it. + * executed more than this amount, the detector will notify you about it. */ 'threshold' => (int) env('QUERY_DETECTOR_THRESHOLD', 1), diff --git a/src/Outputs/Console.php b/src/Outputs/Console.php index 6b4680f..7a90366 100644 --- a/src/Outputs/Console.php +++ b/src/Outputs/Console.php @@ -42,10 +42,10 @@ protected function getOutputContent(Collection $detectedQueries) $output .= "console.warn('Found the following N+1 queries in this request:\\n\\n"; foreach ($detectedQueries as $detectedQuery) { $output .= "Model: ".addslashes($detectedQuery['model'])." => Relation: ".addslashes($detectedQuery['relation']); - $output .= " - You should add \"with(\'".$detectedQuery['relation']."\')\" to eager-load this relation."; + $output .= " - You should add \"with(\'".addslashes($detectedQuery['relation'])."\')\" to eager-load this relation."; $output .= "\\n\\n"; $output .= "Model: ".addslashes($detectedQuery['model'])."\\n"; - $output .= "Relation: ".$detectedQuery['relation']."\\n"; + $output .= "Relation: ".addslashes($detectedQuery['relation'])."\\n"; $output .= "Num-Called: ".$detectedQuery['count']."\\n"; $output .= "\\n"; $output .= 'Call-Stack:\\n'; diff --git a/src/QueryDetector.php b/src/QueryDetector.php index 0d3dcc6..8deb29a 100755 --- a/src/QueryDetector.php +++ b/src/QueryDetector.php @@ -74,6 +74,10 @@ public function logQuery($query, Collection $backtrace) } $sources = $this->findSource($backtrace); + + if (empty($sources)) { + return; + } $key = md5($query->sql . $model . $relationName . $sources[0]->name . $sources[0]->line);