barryvdh / laravel-debugbar

Debugbar for Laravel (Integrates PHP Debug Bar)
MIT License
16.98k stars 1.54k forks source link

Enable laravel debugbar dynamically #1384

Open michaltobiaszfpwd opened 1 year ago

michaltobiaszfpwd commented 1 year ago

Is there any way to disable the debugbar by default and enable it dynamically in the middleware?

When in AppServiceProvider boot I add Debugbar::disable(); and then in the middleware in the condition I add Debugbar::enable(); it does not work.

Replacing config('debugbar.enabled') doesn't work either.

Is it possible to do?

BataBoom commented 1 year ago

Having same issue here. I've tried custom Middleware and AppServiceProvider methods. No dice yet.

irvingzamora commented 1 year ago

Do you want to enable the debugbar only on certain routes?

vatsake commented 1 year ago

Any updates on this?

thearyanahmed commented 6 months ago

You can enable debugbar only on certain routes by passing an array of URIs.

https://github.com/barryvdh/laravel-debugbar/blob/master/config/debugbar.php#L13-L22

Also, maybe you can have a middleware similar to InjectDebugbar. Maybe extend from this middleware and override the handle method to forcefully boot the debugbar?

https://github.com/barryvdh/laravel-debugbar/blob/master/src/Middleware/InjectDebugbar.php

erikn69 commented 6 months ago

When in AppServiceProvider boot I add Debugbar::disable(); and then in the middleware in the condition I add Debugbar::enable(); it does not work.

I do the same, and works But i add on app/Http/kernel.php

protected $middlewarePriority = [
    ///
    \App\Http\Middleware\DebugbarEnabler::class, // my middleware
    \Barryvdh\Debugbar\Middleware\InjectDebugbar::class,
];