New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

tpetry/laravel-mysql-explain

Get Visual MySQL EXPLAIN for Laravel.
250,790 268
Install
composer require tpetry/laravel-mysql-explain
Latest Version:2.2.0
PHP:^8.0
Laravel:6 – 13
License:MIT
Last Updated:Mar 12, 2026
Links: GitHub  ·  Packagist
Maintainer: tpetry

Laravel MySQL Visual Explains

License PHP Laravel Latest Version on Packagist GitHub Unit Tests Action Status GitHub Static Analysis Action Status GitHub Code Style Action Status

MySQL Query optimization with the EXPLAIN command is unnecessarily complicated: The output contains a lot of cryptic information that is incomprehensible or entirely misleading.

This Laravel package collects many query metrics that will be sent to mysqlexplain.com and transformed to be much easier to understand.

Installation

You can install the package via composer:

composer require tpetry/laravel-mysql-explain

Usage

Query Builder

Three new methods have been added to the query builder for very easy submission of query plans:

Type Action
visualExplain returns URL to processed EXPLAIN output
dumpVisualExplain dumps URL to processed EXPLAIN output and continue normal execution
ddVisualExplain dumps URL to processed EXPLAIN output and stops execution
explainForHumans (deprecated) returns URL to processed EXPLAIN output
dumpExplainForHumans (deprecated) dumps URL to processed EXPLAIN output and continue normal execution
ddExplainForHumans (deprecated) dumps URL to processed EXPLAIN output and stops execution
// $url will be e.g. https://mysqlexplain.com/explain/01j2gcrbsjet9r8rav114vgfsy
$url = Film::where('description', 'like', '%astronaut%')
    ->visualExplain();

// URL to EXPLAIN will be printed to screen
$users = Film::where('description', 'like', '%astronaut%')
    ->dumpVisualExplain()
    ->get();

// URL to EXPLAIN will be printed to screen & execution is stopped
Film::where('description', 'like', '%astronaut%')
    ->ddVisualExplain();

Raw Queries

In some cases you are executing raw SQL queries and don't use the query builder. You can use the MysqlExplain facade to get the EXPLAIN url for them:

use Tpetry\LaravelMysqlExplain\Facades\MysqlExplain;

// $url will be e.g. https://mysqlexplain.com/explain/01j2gctgtheyva7a7mhpv8azje
$url = MysqlExplain::submitQuery(
    DB::connection('mysql'),
    'SELECT * FROM actor WHERE first_name = ?',
    ['PENEL\'OPE'],
);

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.

Related Packages

yadakhov/insert-on-duplicate-key

A trait for MySQL INSERT ON DUPLICATE KEY UPDATE.

3,117,053 275
ismael-gonzalez/mysql-queue

A laravel 4.2 queue driver using MySQL database.

35,043 0
huangdijia/laravel-trigger

MySQL trigger base on MySQLReplication.

5,621 32
vuduythanh2020/lumen-trigger

MySQL trigger base on MySQLReplication

3,274 0
molay76/laravel-mysql2plantuml

convert mysql schema to plantuml

3,068 2

Version History

Version Released PHP Laravel License
2.2.0 ^8.0 ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0 MIT
2.1.0 ^8.0 ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0 MIT
2.0.0 ^8.0 ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0 MIT
1.3.2 ^8.0 ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0 MIT
1.3.1 ^8.0 ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0 MIT