Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Debugbar Laravel Package

barryvdh/laravel-debugbar

Laravel Debugbar integrates PHP Debug Bar into Laravel, showing request, queries, views, routes, logs, exceptions, and performance details in a handy toolbar. Great for local debugging and profiling; configurable and easy to enable/disable per environment.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require barryvdh/laravel-debugbar --dev
    

    Add to config/app.php under providers:

    Barryvdh\Debugbar\ServiceProvider::class,
    
  2. Enable Debug Mode: Set APP_DEBUG=true in .env or enable via:

    debugbar()->enable();
    
  3. First Use Case: Dump variables in real-time:

    debug($user, $request->input());
    

    View the debug bar at the bottom of your browser after a request.


Implementation Patterns

Core Workflows

  1. Debugging Variables: Replace dd() or dump() with debug() for non-breaking inspection:

    debug($user->roles); // Appears in "Messages" tab
    
  2. Timing Operations: Measure execution time with measure():

    debugbar()->measure('render-view', function() {
        return view('dashboard');
    });
    
  3. Database Queries: Enable db collector in config/debugbar.php to log queries with:

    • Bindings
    • Execution time
    • File backtrace (where the query originated)
  4. Exception Handling: Log uncaught exceptions automatically or manually:

    try { ... } catch (\Exception $e) {
        debugbar()->addThrowable($e);
    }
    

Integration Tips

  • Conditional Debugging: Disable debugbar in production via .env:

    APP_DEBUG=false
    

    Or runtime:

    debugbar()->disable();
    
  • Custom Collectors: Extend functionality by adding collectors (e.g., for third-party services):

    debugbar()->addCollector(new \App\Debugbar\CustomCollector());
    
  • Console Usage: Enable debugbar in Artisan commands:

    debugbar()->enable();
    // ... command logic ...
    debugbar()->disable();
    
  • Livewire Integration: Automatically captures Livewire component events and state changes.


Gotchas and Tips

Pitfalls

  1. Performance Overhead:

    • Disable unused collectors in config/debugbar.php (e.g., events, cache).
    • Use soft_limit/hard_limit for queries to avoid memory bloat:
      'db' => [
          'soft_limit' => 50,  // Stop capturing bindings after 50 queries
          'hard_limit' => 200, // Ignore queries after 200
      ]
      
  2. Storage Risks:

    • Never enable storage.open in production—it exposes request history.
    • Restrict access via IP or middleware:
      debugbar()->setStorageCallback(function ($request) {
          return $request->ip() === '127.0.0.1';
      });
      
  3. Query Backtrace Exclusions:

    • Exclude vendor paths to avoid clutter:
      'db' => [
          'backtrace_exclude_paths' => [
              'vendor/laravel/framework',
              'vendor/doctrine',
          ],
      ]
      
  4. Twig Debugging:

    • Replace {{ dump(var) }} with {{ debug(var) }} to avoid rendering in production.

Debugging Tips

  • Isolate Slow Queries: Use slow_threshold to highlight slow queries:

    'db' => [
        'slow_threshold' => 50, // Mark queries >50ms as slow
    ]
    
  • EXPLAIN Queries: Enable on-demand EXPLAIN for complex queries (experimental):

    'db' => [
        'explain' => ['enabled' => true],
    ]
    
  • Memory Profiling: Enable the memory collector to track usage spikes:

    'collectors' => [
        'memory' => true,
    ]
    
  • Custom Messages: Categorize messages with labels:

    debugbar()->addMessage('User created', 'auth', 'success');
    

Extension Points

  1. Custom Collectors: Implement DebugBar\DataCollector\DataCollectorInterface:

    class MyCollector implements DataCollectorInterface {
        public function collect() { ... }
        public function getName() { return 'my_collector'; }
    }
    
  2. Override Templates: Publish and modify debugbar views:

    php artisan vendor:publish --tag=debugbar.views
    
  3. Hook into Events: Listen for debugbar.collect events to inject data dynamically:

    Event::listen('debugbar.collect', function ($debugbar) {
        $debugbar->addCollector(new MyDynamicCollector());
    });
    
  4. Console Output: Redirect debugbar data to CLI for headless debugging:

    debugbar()->setOutputBuffering(false);
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle