laravel-query-adviser
laravel-query-adviser copied to clipboard
With Laravel Query Adviser you can get more insights into the SQL queries created by Eloquent models used in your app. It logs the queries used by your application and provides a helpful overview of t...
Laravel-Query-Adviser
With Laravel Query Adviser you can get more insights into the SQL queries created by Eloquent models used in your app. It logs the queries used by your application and provides a helpful overview of the SQL queries. You can rerun the SQL query to analyze the database impact or copy the SQL query to your clipboard. The handy card view allows you to quickly point out the pain points of your application's SQL queries. |
Features
Query Logging | Web app | Chrome DevTool | Code |
---|---|---|---|
Use cache driver | |||
Eloquent Queries | |||
Routes | |||
Stack trace | |||
Tinker Support | |||
Job Support | |||
MySql Support | |||
Start session | Start Session | ||
Stop session | Stop Session | ||
Export Session | |||
Import Session | |||
Query Grouping | |||
Query Ordering | |||
Explain Query | |||
Re-execute Query | |||
Copy to clipboard | |||
Show realtime query usage | |||
dd query builder query | |||
dump query builder query | |||
dd eloquent model query | |||
dump eloquent model query |
Installation
You can install the package via composer:
composer require socialblue/laravel-query-adviser --dev
Publish Laravel-Query-Adviser
php artisan vendor:publish --provider="Socialblue\LaravelQueryAdviser\LaravelQueryAdviserServiceProvider"
Publish the front-end application after updating
php artisan vendor:publish --tag=public --force
When updating from 0.13.2
to 0.14.0
please use
php artisan vendor:publish --provider="Socialblue\LaravelQueryAdviser\LaravelQueryAdviserServiceProvider" --force
Install Chrome developer tool
When you want to be able to start and stop the log sessions and see realtime query information from your current browser tab. You can install the Chrome developer tool in the Chrome web store.
Usage
Output queries inline
Dump and die
User::join('posts', 'posts.users_id', '=', 'users.id') ->select([DB::raw('SUM(posts.id)')]) ->where('users.id', 1) ->select([DB::raw('SUM(post.id)')])->qadd();
or just dump
User::join('posts', 'posts.users_id', '=', 'users.id') ->select([DB::raw('SUM(posts.id)')]) ->where('users.id', 1) ->select([DB::raw('SUM(post.id)')])->qadump();
both dump this array
[ 'toSql' => 'select sum(posts.id) from users join posts on posts.users_id = users.id where users.id = ?' 'bindings' => [1] 'query' => 'select sum(posts.id) from users join posts on posts.users_id = users.id where users.id = 1' ]
Start query logging session
- To start a query log session goto {app_url}/query-adviser/
- Press play and open the pages of your app you want to log the queries of
- Stop the session and click on the session bar to see all the details.
Session stepper
Session list
Brows through session overview
Query time-line
collapse and expand the panels for less or more information about the queries executed in that time frame.
Groups
You can group the queries by time, routes and rawQuery. Also you can clear the cached queries by pressing the eject button.
group by time, routes, referer, raw queries, queries with bindings, and query time
Sort
Sort the time line by last inserted, slowest query, and most occurrences
Query card
Re-execute a query, get query information, and copy the query to your clipboard
Query labels
As of version 0.10.0, the query card has labels related to the class, file and function of the query executed from your app folder.
File Information
Open the explain dialog to see more information about the query.
Query information
Re-execute Query
Testing
composer test
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Mark
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.