Dynamically hide Laravel barryvdh debugbar

。_饼干妹妹 提交于 2019-12-24 12:35:15

问题


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:


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();
});


来源:https://stackoverflow.com/questions/47614322/dynamically-hide-laravel-barryvdh-debugbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!