Laravel Debugbar

repository·master·Indexed 12 days ago

https://github.com/fruitcake/laravel-debugbar

A package that integrates the PHP Debug Bar with Laravel, providing specialized collectors for Laravel-specific data such as queries, routes, views, and events. It includes a facade for logging and timing, support for Laravel Octane 4.x, and various data collectors for monitoring memory usage, cache hits, Eloquent models, and more.

Tokens
11.2K
Snippets
37
Records
70
Agent score
98%

What's inside Laravel Debugbar

  1. How Debugbar activation works

    master

    By default, the Debugbar is automatically enabled only when:

    1. APP_DEBUG is set to true.
    2. The environment is not production or testing.

    Manual Control:

    • You can disable it via the debugbar.enabled config key or the DEBUGBAR_ENABLED environment variable.
    • If you need to enable it in a production environment (not recommended), you must set debugbar.force_allow_enable to true or use the DEBUGBAR_FORCE_ALLOW_ENABLE=true environment variable. This allows the ServiceProvider to bootstrap so you can call Debugbar::enable() at runtime.
  2. Use on-demand query EXPLAIN

    master

    By enabling options.db.explain.enabled in your configuration, you can run on-demand EXPLAIN queries for any SELECT statement directly within the Debugbar interface. This helps in analyzing query performance and provides a link to mysqlexplain.com for visual explanation.

    'options' => [
        'db' => [
            'explain' => [
                'enabled' => true,
            ],
        ],
    ],
  3. Migrate from 3.x to 4.x

    master

    When upgrading from version 3.x to 4.x, note the following breaking changes:

    • Dependencies: The php-debugbar dependency is now 3.x, which removes jQuery and font-awesome. If you use custom collectors, ensure they do not rely on these assets.
    • Namespace: The namespace has changed from Barryvdh\Debugbar to Fruitcake\LaravelDebugbar. You only need to update this if you are manually registering the Service Provider or the Facade.
    • Package Name: The composer package name is now fruitcake/laravel-debugbar.
    • Removed Features:
      • SocketStorage is removed.
      • Lumen support is removed.
      • FileCollector is removed.
      • Global helper methods start_measure(), add_measure(), stop_measure(), and measure() are removed. Use debugbar()->startMeasure() and related methods instead.
  4. Extend Laravel Debugbar in version 4.x

    master

    If you are developing a package that extends Laravel Debugbar, you must implement the following changes for version 4.x:

    • Response Handling: The modifyResponse method has been renamed to handleResponse. It is now implemented via a listener rather than middleware.
    • HTTP Driver: The HttpDriver is now session-less and utilizes cookies.
    • Laravel Octane: Because Octane maintains the LaravelDebugbar state, collectors must be reset. You can now remove LaravelDebugbar from your application's flush configuration.
  5. Install without Package Auto-Discovery

    master

    If your Laravel installation does not use auto-discovery, you must manually register the ServiceProvider:

    • Laravel 11 or newer: Add Fruitcake\LaravelDebugbar\ServiceProvider::class to bootstrap/providers.php.
    • Laravel 10 or older: Add Fruitcake\LaravelDebugbar\ServiceProvider::class to the providers array in config/app.php.

    To use the Debugbar facade for logging messages, register an alias in the register method of your app/Providers/AppServiceProvider.php:

    public function register(): void
    {
        $loader = \Illuminate\Foundation\AliasLoader::getInstance();
        $loader->alias('Debugbar', \Fruitcake\LaravelDebugbar\Facades\Debugbar::class);
    }
  6. Laravel Debugbar with Octane

    master

    Laravel Debugbar 4.x supports Laravel Octane out of the box without additional configuration.

    Migration Note: If you are upgrading from version 3.x, you must remove the 'flush' configuration for Debugbar from your config/octane.php file.

  7. Enable or disable Laravel Debugbar

    master

    By default, Debugbar is enabled when APP_DEBUG is set to true in your environment.

    You can explicitly control its state using the following methods:

    1. Environment Variable: Set DEBUGBAR_ENABLED in your .env file.
    2. Configuration File: Set the enabled key in config/debugbar.php.

    If you use a catch-all or fallback route, ensure the Debugbar ServiceProvider is loaded before your own application ServiceProviders.

    // config/debugbar.php
    'enabled' => env('DEBUGBAR_ENABLED', null),
    
    // You can also define URIs to ignore
    'except' => [
        'telescope*',
        'horizon*',
    ],