Laravel-debugbar: Track where database queries are coming from

Created on 1 Apr 2016  路  7Comments  路  Source: barryvdh/laravel-debugbar

Is there a way to track what class/file a database query was called?

This will surely help a lot.

stale

Most helpful comment

Did you try the db backtrace option in the config?

All 7 comments

Did you try the db backtrace option in the config?

Thanks! Exactly what I needed :+1:

May I raise a similar issue here?

I find the backtrace option very very useful, but I often need to backtrace a few more steps down the stack. E.g. I'm dealing with a legacy codebase, and I have several queries that are executed on my eloquent models (on relations or other methods).

That usually is a code smell that indicates that eager loading should be applied before calling those methods. But due to the spagghetti nature of that codebase, it's not easy to find the controllers or the intermediate classes which call those methods on the models. If I could backtrace a few levels back that would be very helpful.

Specifically, the QueryCollector@findSource could collect all the meaningful stack lines (instead of returning one the first one). The debug_backtrace method accepts a $limit parameter, which could be set in the config.

Then on the queries tab, the first backtrace result would be displayed (like it is currently). but when expading on a query, the stack trace could be listed along with the SQL and the bindings too.

I could submit a PR if you find that idea useful.

Hmm could be interesting. Just a bit worried about the information overload..

I understand your concern, but as a designer (also) I could give it a try to make the information look neat.
Currently, the way the query information is displayed on expansion is a bit clunky. The params <table> is prepended to the left and is causing the hints to look weird.

Ok, I'm open for suggestions and improvements :)

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this issue is still present on the latest version of this library on supported Laravel versions, please let us know by replying to this issue so we can investigate further.
Thank you for your contribution! Apologies for any delayed response on our side.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lozadaOmr picture lozadaOmr  路  6Comments

Megachill picture Megachill  路  3Comments

kjhatis picture kjhatis  路  5Comments

linaspasv picture linaspasv  路  5Comments

ddmo picture ddmo  路  3Comments