Dynamically hide Laravel barryvdh debugbar

2019-07-29 18:36发布

I could not able to hide Laravel Debugbar dynamically, i.e on the run time. I have tried the following from parent Controller class constructor:

<?php

namespace App\Http\Controllers;
class Controller extends BaseController {

    use AuthorizesRequests,
        DispatchesJobs,
        ValidatesRequests;
    public $foo = 'null';

    public function __construct() {
        \Debugbar::disable();
      // and also
      config(['debugbar.enabled' => false]);
.... 

All of the above tries failed. I'd like to mention that controller is the parent controller of all other controllers' classes.

The only working way is not dynamic way, where I have to change configuration manually. I don't know why the override configurations doesn work as the documentation states?

1条回答
姐就是有狂的资本
2楼-- · 2019-07-29 19:07

Without seeing all you code, yours should work. Here is how I configure mine to work in a local environment and disable it with specific requests.

AppServiceProvider

use Barryvdh\Debugbar\ServiceProvider as DebugbarServiceProvider;

...

public function register()
{
  if ($this->app->environment('local')) {
    $this->app->register(DebugbarServiceProvider::class);
  }
}

Where I would like to disable I put.

use Barryvdh\Debugbar\Facade as Debugbar;

...

if (App::environment('local')) {
  Debugbar::disable();
}

Update per comment

Why do you put something in your routes file like this.

use Barryvdh\Debugbar\Facade as Debugbar;

...

Route::group(array('domain' => 'admin.example.com'), function()
{
   Debugbar::disable();
});
查看更多
登录 后发表回答