-
Notifications
You must be signed in to change notification settings - Fork 140
Integration with ajax requests #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
||
$validateContentTypeHTML = true; | ||
|
||
if (env('QUERY_DETECTOR_AJAX', false)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to use config(...)
, not env(...)
because when config are cached env()
will always return null
.
Config reference:
https://laravel.com/docs/7.x/configuration#configuration-caching
|
||
return $output; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty line :(
$output .= "\\n"; | ||
if (!request()->ajax()) { | ||
$output = '<script type="text/javascript">'; | ||
$output .= "alert('Found the following N+1 queries in this request:\\n\\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest another way.
Maybe blade template will look better?
$output .= "Model: ".addslashes($detectedQuery['model'])." => Relation: ".addslashes($detectedQuery['relation']); | ||
$output .= " - You should add \"with(\'".addslashes($detectedQuery['relation'])."\')\" to eager-load this relation."; | ||
$output .= "\\n"; | ||
if (!request()->ajax()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate check for request()->ajax()
|
||
``` javascript | ||
$(document).ajaxComplete(function(event, response){ | ||
if (typeof response.responseJSON.laravelQueryDetector != 'undefined') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (typeof response.responseJSON.laravelQueryDetector != 'undefined') { | |
if (typeof response.responseJSON.laravelQueryDetector !== 'undefined') { |
What's the status of this PR? I'd love to use query-detector but most of my requests are async via javascript so right now it basically detects nothing. |
I'll close this. Feel free to do create another PR with the reviewed suggestions and tests. |
Integration with ajax requests to show the alert when an N+1 is detected