ka4ivan / laravel-api-debugger
A debugging tool for Laravel APIs that provides request execution time and query profiling.
1.0.3
2025-03-28 18:34 UTC
Requires
- php: ^8.0.2
- illuminate/support: ^9.0|^10.0|^11.0|^12.0
README
Installation
- Require this package with composer
composer require ka4ivan/laravel-api-debugger --dev
- Debug works if the
APP_DEBUG
=true
How it works
- The debugger will start logging SQL queries and request data for every API request.
- It will only activate if
APP_DEBUG=true
in your.env
file. - The results, including query count, execution time, and detailed data, will be attached to the API response for debugging purposes.
Example
When you send an API request and APP_DEBUG=true
, you'll receive the following debug data in the response:
{ "data": { "..." }, "debugger": { "queries": { "count": 8, "time": 14.57, "data": [ { "query": "select * from `domains` where `is_active` = ? limit 1", "bindings": [ true ], "time": 10.09 }, { "query": "select * from `products` limit 1", "bindings": [], "time": 0.75 }, { "query": "select * from `menu_items` where (`domain_id` = ? or `domain_id` is null) order by `weight` asc", "bindings": [ "8e591823-4f64-4e90-b564-e0c090696d6e" ], "time": 0.82 }, { "query": "select * from `pages` where `slug` = ? and (`domain_id` = ? or `domain_id` is null) and `status` = ? order by `weight` asc, `created_at` asc limit 1", "bindings": [ "contacts", "8e591823-4f64-4e90-b564-e0c090696d6e", "published" ], "time": 0.76 }, { "query": "select * from `comparisons` where `guest_id` = ?", "bindings": [ "62afacc1-37b2-464d-8028-818745e56de5" ], "time": 0.61 }, { "query": "select * from `comparisons` where `guest_id` = ?", "bindings": [ "62afacc1-37b2-464d-8028-818745e56de5" ], "time": 0.61 }, { "query": "select * from `comparisons` where `guest_id` = ?", "bindings": [ "62afacc1-37b2-464d-8028-818745e56de5" ], "time": 0.63 }, { "query": "select * from `seos` where `path` = ? limit 1", "bindings": [ "" ], "time": 0.93 } ], "long_queries": [ { "query": "select * from `domains` where `is_active` = ? limit 1", "bindings": [ true ], "time": 10.09 } ], "n_plus_one": [ { "query": "select * from `comparisons` where `guest_id` = ?", "count": 3 } ] }, "request": { "body": [], "headers": { "connection": [ "keep-alive" ], "accept-encoding": [ "gzip, deflate, br" ], "host": [ "dev-packages.test" ], "postman-token": [ "8654756-6abf-4511-9b91-72865463" ], "user-agent": [ "PostmanRuntime/7.37.3" ], "authorization": [ "Bearer 8|vxwhATRrOfinZiR4zvhoTpckGqYJTPnmj9tkOfdMb5d9da28" ], "accept": [ "application/json" ] } } } }
License
This package is licensed under the MIT License. You can freely use, modify, and distribute this package, provided that you include a copy of the license in any redistributed software.