Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fitztrev/query-tracer
Find exactly where a specific database query is being called in your Laravel application.
https://github.com/fitztrev/query-tracer
Last synced: 14 days ago
JSON representation
Find exactly where a specific database query is being called in your Laravel application.
- Host: GitHub
- URL: https://github.com/fitztrev/query-tracer
- Owner: fitztrev
- Created: 2016-05-09T00:52:34.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-05-22T17:10:58.000Z (over 8 years ago)
- Last Synced: 2024-10-05T11:07:18.101Z (about 1 month ago)
- Language: PHP
- Homepage:
- Size: 9.77 KB
- Stars: 229
- Watchers: 7
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Laravel Query Tracer
[![Build Status](https://travis-ci.org/fitztrev/query-tracer.svg?branch=master)](https://travis-ci.org/fitztrev/query-tracer) [![Latest Stable Version](https://poser.pugx.org/fitztrev/query-tracer/v/stable)](https://packagist.org/packages/fitztrev/query-tracer)
Find exactly *where* a specific database query is being called in your Laravel application.
Want to optimize or debug your database queries but not sure where they're being called? See how it works below with [Clockwork](https://github.com/itsgoingd/clockwork):
![](http://i.imgur.com/0cRs7TU.png)
If you use [Debugbar](https://github.com/barryvdh/laravel-debugbar), it has this functionality built-in if you set `debugbar.options.db.backtrace` to `true`.
### Installation
1. Install via composer:
```bash
composer require fitztrev/query-tracer
```2. Add the service provider to your `config/app.php`:
```php
'providers' => [
// ...
Fitztrev\QueryTracer\Providers\QueryTracerServiceProvider::class,
],
```### How does it do it?
It makes use of Laravel's global query scopes to do a backtrace and find where a query originated. Then it puts that info in extraneous but helpful `WHERE` clauses.
By default, it's only enabled when `debug` is on. You can change this behavior for specific models by adding an `enableQueryTracer()` method to your model(s). For example:
```php
public function enableQueryTracer()
{
return config('app.env') == 'local';
}
```