Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Queries in providers #1492

Open
Brand3000 opened this issue Oct 29, 2023 · 11 comments
Open

Queries in providers #1492

Brand3000 opened this issue Oct 29, 2023 · 11 comments

Comments

@Brand3000
Copy link

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

@parallels999
Copy link
Contributor

parallels999 commented Nov 6, 2023

Change providers priority order

@Brand3000
Copy link
Author

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

@parallels999
Copy link
Contributor

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

that is due to laravel autodiscover

@Brand3000
Copy link
Author

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

@Brand3000 Brand3000 changed the title Queries in providera Queries in providers Jan 26, 2024
@Brand3000
Copy link
Author

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?

@parallels999
Copy link
Contributor

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

@Brand3000
Copy link
Author

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

@D39-Dev
Copy link

D39-Dev commented Mar 6, 2024

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

@erikn69
Copy link
Contributor

erikn69 commented Mar 6, 2024

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

@D39-Dev
Copy link

D39-Dev commented Mar 14, 2024

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.

@Seb33300
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants