fruitcake/laravel-debugbar
Integrate PHP DebugBar into Laravel with minimal setup to inspect requests, queries, views, routes, and logs in a handy toolbar. Includes collectors, timing, memory, and profiling tools to quickly find bottlenecks during development.
Installation:
composer require fruitcake/laravel-debugbar
Publish the config:
php artisan vendor:publish --provider="Fruitcake\LaravelDebugbar\ServiceProvider" --tag="config"
Enable Debug Mode:
Set APP_DEBUG=true in your .env file.
First Use Case:
Trigger a request (e.g., visit /). The debug bar will appear at the bottom of the screen, displaying default collectors like Queries, Messages, Views, and Exceptions.
New Feature: SQL query backtraces now include editor links for direct navigation to the query's origin in your IDE (if configured).
debug($variable) or Debugbar::info($data) to log data.Debugging Queries:
// Log a query manually
Debugbar::addQuery('SELECT * FROM users', ['bindings' => []]);
New: Queries now show direct editor links (if remote_sites_path/local_sites_path are configured).
Timing Operations:
Debugbar::startMeasure('render', 'Time to render view');
// ... your code ...
Debugbar::stopMeasure('render');
Custom Collectors:
// Add a custom collector
Debugbar::addCollector(new \DebugBar\DataCollector\CustomCollector());
Conditional Debugging:
if (app()->environment('local')) {
debugbar()->enable();
}
Middleware: Use Debugbar::enable() in middleware for specific routes.
public function handle(Request $request, Closure $next) {
debugbar()->enable();
return $next($request);
}
Console Commands:
debugbar()->enable();
// ... command logic ...
Twig Integration:
{{ debug(user) }} {# Logs user data #}
{% stopwatch "process" %}
{# Timed block #}
{% endstopwatch %}
Livewire: Automatically captures Livewire component interactions.
Editor Links for SQL:
Ensure remote_sites_path and local_sites_path are configured in config/debugbar.php for IDE navigation:
'remote_sites_path' => [
'github.com' => 'https://github.com/{username}/{repo}/blob/{branch}/',
],
'local_sites_path' => [
'/var/www/project' => 'http://localhost/project/',
],
Performance Overhead:
config/debugbar.php (e.g., collectors.phpinfo = false).debugbar()->disable() in non-local environments.Storage Security:
storage.open = true in production or shared environments.'storage' => [
'open' => function ($request) {
return $request->ip() === '127.0.0.1';
},
],
AJAX Requests:
capture_ajax if experiencing issues with XHR requests:
'capture_ajax' => false,
Editor Links Configuration:
remote_sites_path/local_sites_path mappings. For Docker/Homestead, ensure paths are container-relative.Disable Collectors Temporarily:
debugbar()->disableCollector('queries'); // Disable queries collector
Clear Storage:
php artisan debugbar:clear
Check for Conflicts:
barryvdh/laravel-debugbar) are installed simultaneously.Custom Data Formatters: Override default formatting for specific classes:
Debugbar::addDataFormatter(new \DebugBar\Data\Formatter\CustomFormatter());
Custom Collectors:
Extend \DebugBar\DataCollector\BaseCollector to create reusable collectors.
Theme Overrides: Override the default theme by publishing assets:
php artisan vendor:publish --provider="Fruitcake\LaravelDebugbar\ServiceProvider" --tag="public"
Environment-Specific Config:
Use .env variables to toggle features dynamically:
DEBUGBAR_COLLECT_JOBS=true
DEBUGBAR_THEME=dark
Event Listeners:
Hook into Debugbar::collectors to modify collectors at runtime:
Debugbar::collectors(function ($collectors) {
$collectors->remove('phpinfo');
});
Editor Links for SQL:
Extend remote_sites_path/local_sites_path to support custom IDE setups (e.g., VS Code, PHPStorm). Example:
'remote_sites_path' => [
'gitlab.com' => 'https://gitlab.com/{username}/{repo}/-/blob/{branch}/',
],
How can I help you explore Laravel packages today?