laravel-debugbar icon indicating copy to clipboard operation
laravel-debugbar copied to clipboard

Queries in providers

Open Brand3000 opened this issue 1 year ago • 11 comments

Hi! The package doesn't show sql queries which are run from providers. Sometimes it's inconvenience. Is it possible to fix this?

Brand3000 avatar Oct 29 '23 18:10 Brand3000

Change providers priority order

parallels999 avatar Nov 06 '23 19:11 parallels999

What do you mean? Actually, I didn't add any debugbar provider. It just works.

Brand3000 avatar Nov 07 '23 08:11 Brand3000

I didn't add any debugbar provider. It just works.

that is due to laravel autodiscover

parallels999 avatar Nov 07 '23 13:11 parallels999

I understand, but it's set up out of the box

Brand3000 avatar Nov 10 '23 08:11 Brand3000

I have done:

  1. added the package in composer.json "dont-discover": ["barryvdh/laravel-debugbar"] and compoer update
  2. Added Barryvdh\Debugbar\ServiceProvider::class, in the config/app.php, the first in the list
  3. Added a test in the AppServiceProvider.php, boot() function: DB::table('user')->where('id', 1)->first();

But I still don't see this sql-request in the Queries tab of DebugBar =(

Where am I in the wrong?

Brand3000 avatar Jan 26 '24 20:01 Brand3000

Dont add it to config/app.php, try adding this on AppServiceProvider boot first line

if(class_exists(\Barryvdh\Debugbar\ServiceProvider::class)){
    $this->app->register(new \Barryvdh\Debugbar\ServiceProvider($this->app));
}

parallels999 avatar Jan 26 '24 20:01 parallels999

Dont add it to config/app.php, try adding this on AppServiceProvider boot first line

if(class_exists(\Barryvdh\Debugbar\ServiceProvider::class)){
    $this->app->register(new \Barryvdh\Debugbar\ServiceProvider($this->app));
}

Unfortunately, it doesn't help =( I tried this code:

public function boot(): void
    {
        if (class_exists(\Barryvdh\Debugbar\ServiceProvider::class)) {
            $this->app->register(new \Barryvdh\Debugbar\ServiceProvider($this->app));
        }
        DB::table('user')->where('id', 1)->first();
    }

and I tried DB::table('user')->where('id', 1)->first(); in another service provider down the queue. It doesn't work, 0 queries

Brand3000 avatar Jan 26 '24 21:01 Brand3000

no solution for this yet? having the same issue :(

D39-Dev avatar Mar 06 '24 14:03 D39-Dev

It doesn't seem like a bug

Added a test in the AppServiceProvider.php, boot() function: DB::table('user')->where('id', 1)->first(); But I still don't see this sql-request in the Queries tab of DebugBar =( Where am I in the wrong?

ServiceProvider::boot is executed before LaravelDebugbar::boot, so debugbar isn't collecting data, therefore those sqls will not be in debugbar

You could force the debugbar boot in AppServiceProvider::boot

$this->app->make(\Barryvdh\Debugbar\LaravelDebugbar::class)->boot();
// After this line debugbar starts collecting
DB::table('user')->where('id', 1)->first();

But I don't know what disadvantages it would bring, maybe some collector does not register correctly, you would have to test it

erikn69 avatar Mar 06 '24 16:03 erikn69

It doesn't seem like a bug

Added a test in the AppServiceProvider.php, boot() function: DB::table('user')->where('id', 1)->first(); But I still don't see this sql-request in the Queries tab of DebugBar =( Where am I in the wrong?

ServiceProvider::boot is executed before LaravelDebugbar::boot, so debugbar isn't collecting data, therefore those sqls will not be in debugbar

You could force the debugbar boot in AppServiceProvider::boot

$this->app->make(\Barryvdh\Debugbar\LaravelDebugbar::class)->boot();
// After this line debugbar starts collecting
DB::table('user')->where('id', 1)->first();

But I don't know what disadvantages it would bring, maybe some collector does not register correctly, you would have to test it

Thanks, this is true, this is not a bug since in my case all queries are being executed at the app's boot time prior to Debugbar booting, and this solution helps a lot, thanks! My case was collecting data for ViewSeriveProvider.

D39-Dev avatar Mar 14 '24 14:03 D39-Dev

There is still no config option to setup the priority without modifying AppServiceProvider?

Seb33300 avatar Apr 10 '24 03:04 Seb33300