Skip to content

Instantly share code, notes, and snippets.

@ivanhoe011
Last active March 29, 2024 12:42
Show Gist options
  • Save ivanhoe011/7dff74f3c3c345f01c83dfc51995c2ea to your computer and use it in GitHub Desktop.
Save ivanhoe011/7dff74f3c3c345f01c83dfc51995c2ea to your computer and use it in GitHub Desktop.
Workaround for Laravel's dd() debugging in new versions of Chrome
<?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