Last active
March 29, 2024 12:42
-
-
Save ivanhoe011/7dff74f3c3c345f01c83dfc51995c2ea to your computer and use it in GitHub Desktop.
Workaround for Laravel's dd() debugging in new versions of Chrome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* New versions of Chrome will not render html responses inside of ajax requests that requested json, which | |
* breaks Laravel's dd() helper method as well as eloquents' ->dd() methods, making it far more complicated | |
* to see what the generated SQL looks like. This is a simple workaround: | |
*/ | |
// instead of `dd($foo);` | |
return response()->json($foo, 500); | |
// instead of ->dd() in the Builder | |
Foo::where('foo', 'bar') | |
->tap(function ($query) { | |
http_response_code(500); | |
echo json_encode(['SQL: ' => $query->toSql(), 'Bindings: ' => $query->getBindings()]); | |
exit; | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment