### Install Laravel Debugbar Source: https://github.com/barryvdh/laravel-debugbar/blob/master/readme.md Installs the laravel-debugbar package using Composer. It is recommended to install this package only for development environments. ```shell composer require barryvdh/laravel-debugbar --dev ``` -------------------------------- ### Helper Functions for Debugging Source: https://github.com/barryvdh/laravel-debugbar/blob/master/readme.md Provides examples of using helper functions for dumping variables and measuring code execution time. The `debug()` function dumps arguments, and the `collect()->debug()` method dumps a collection. ```php debug($var1, $someString, $intValue, $object); collect([$var1, $someString])->debug(); start_measure('render','Time for rendering'); stop_measure('render'); add_measure('now', LARAVEL_START, microtime(true)); measure('My long operation', function() { // Do something… }); ``` -------------------------------- ### Adding Messages and Timing Source: https://github.com/barryvdh/laravel-debugbar/blob/master/readme.md Demonstrates how to add various types of messages (info, error, warning) and custom messages with labels using the Debugbar facade. It also shows how to start, stop, and add timing measurements for code execution. ```php Debugbar::info($object); Debugbar::error('Error!'); Debugbar::warning('Watch out…'); Debugbar::addMessage('Another message', 'mylabel'); Debugbar::startMeasure('render','Time for rendering'); Debugbar::stopMeasure('render'); Debugbar::addMeasure('now', LARAVEL_START, microtime(true)); Debugbar::measure('My long operation', function() { // Do something… }); ``` -------------------------------- ### Configuration Loading Source: https://github.com/barryvdh/laravel-debugbar/blob/master/readme.md Loads the debugbar configuration file for Lumen applications. This allows customization of the debugbar's behavior by copying the config file to your config folder. ```php $app->configure('debugbar'); ``` -------------------------------- ### Publish Configuration Source: https://github.com/barryvdh/laravel-debugbar/blob/master/readme.md Copies the package's configuration file to your local config directory, allowing for customization of Debugbar settings. ```shell php artisan vendor:publish --provider="Barryvdh\Debugbar\ServiceProvider" ``` -------------------------------- ### Logging Exceptions Source: https://github.com/barryvdh/laravel-debugbar/blob/master/readme.md Shows how to log exceptions using the Debugbar. This is useful for capturing and displaying error details within the debugbar interface. ```php try { throw new Exception('foobar'); } catch (Exception $e) { Debugbar::addThrowable($e); } ``` -------------------------------- ### Register Debugbar Facade Source: https://github.com/barryvdh/laravel-debugbar/blob/master/readme.md Registers the Debugbar facade for easy logging of messages, exceptions, and time within Laravel applications. This should be added to the `register` method of `app/Providers/AppServiceProvider.php`. ```php public function register(): void { $loader = \Illuminate\Foundation\AliasLoader::getInstance(); $loader->alias('Debugbar', \Barryvdh\Debugbar\Facades\Debugbar::class); } ``` -------------------------------- ### Lumen Service Provider Registration Source: https://github.com/barryvdh/laravel-debugbar/blob/master/readme.md Registers the Debugbar service provider for Lumen applications. This should be done within the bootstrap/app.php file if the APP_DEBUG environment variable is true. ```php if (env('APP_DEBUG')) { $app->register(Barryvdh\Debugbar\LumenServiceProvider::class); } ``` -------------------------------- ### Enabling and Disabling Debugbar at Runtime Source: https://github.com/barryvdh/laravel-debugbar/blob/master/readme.md Demonstrates how to programmatically enable or disable the Debugbar during application execution. This is useful for conditional debugging. ```php \Debugbar::enable(); \Debugbar::disable(); ``` -------------------------------- ### Twig Stopwatch Tag Source: https://github.com/barryvdh/laravel-debugbar/blob/master/readme.md Demonstrates the usage of the `stopwatch` tag in Twig templates for timing specific blocks of code, similar to Symfony's Stopwatch component. ```twig {% stopwatch "foo" %} …some things that gets timed {% endstopwatch %} ``` -------------------------------- ### Manual Javascript Renderer Source: https://github.com/barryvdh/laravel-debugbar/blob/master/readme.md Shows how to obtain the Javascript renderer for manual injection of the Debugbar into the HTML. This is used when the auto-injection feature is disabled. ```php $renderer = Debugbar::getJavascriptRenderer(); ``` -------------------------------- ### Twig Debug and Dump Functions Source: https://github.com/barryvdh/laravel-debugbar/blob/master/readme.md Shows how to use the `debug()` and `dump()` functions within Twig templates. `debug()` passes variables to the Message Collector, while `dump()` outputs variables using the DataFormatter. ```twig {{ debug() }} {{ debug(user, categories) }} ``` -------------------------------- ### Register Service Provider (Laravel 11+) Source: https://github.com/barryvdh/laravel-debugbar/blob/master/readme.md Manually registers the Debugbar ServiceProvider in Laravel 11 or newer applications that do not use package auto-discovery. This is done in the bootstrap/providers.php file. ```php return [ // ... Barryvdh\Debugbar\ServiceProvider::class, ]; ``` -------------------------------- ### Laravel Octane Configuration Source: https://github.com/barryvdh/laravel-debugbar/blob/master/readme.md Configures Laravel Debugbar to work with Laravel Octane by adding the Debugbar's class to the flush list in `config/octane.php`. This ensures the Debugbar is properly reset between requests. ```php 'flush' => [ \Barryvdh\Debugbar\LaravelDebugbar::class, ], ``` -------------------------------- ### Twig Integration Extensions Source: https://github.com/barryvdh/laravel-debugbar/blob/master/readme.md Lists the Twig extensions provided by Laravel Debugbar for integration with TwigBridge. These extensions enhance debugging capabilities within Twig templates. ```twig 'Barryvdh\Debugbar\Twig\Extension\Debug', 'Barryvdh\Debugbar\Twig\Extension\Dump', 'Barryvdh\Debugbar\Twig\Extension\Stopwatch', ``` -------------------------------- ### Register Service Provider (Laravel < 11) Source: https://github.com/barryvdh/laravel-debugbar/blob/master/readme.md Manually registers the Debugbar ServiceProvider in Laravel applications that do not use package auto-discovery. This is for Laravel versions 10 or older. ```php Barryvdh\Debugbar\ServiceProvider::class, ``` -------------------------------- ### Adding Custom DataCollectors Source: https://github.com/barryvdh/laravel-debugbar/blob/master/readme.md Illustrates how to add custom DataCollectors to the Debugbar, either through the Facade or the App container. This allows extending the debugbar's functionality with custom data. ```php Debugbar::addCollector(new DebugBar\DataCollector\MessagesCollector('my_messages')); //Or via the App container: $debugbar = App::make('debugbar'); $debugbar->addCollector(new DebugBar\DataCollector\MessagesCollector('my_messages')); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.