PHPackages                             tpetry/laravel-mysql-explain - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. tpetry/laravel-mysql-explain

ActiveLibrary[Database &amp; ORM](/categories/database)

tpetry/laravel-mysql-explain
============================

Get Visual MySQL EXPLAIN for Laravel.

2.2.0(3mo ago)265172.8k↓14.9%8[1 PRs](https://github.com/tpetry/laravel-mysql-explain/pulls)MITPHPPHP ^8.0CI failing

Since Jun 12Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/tpetry/laravel-mysql-explain)[ Packagist](https://packagist.org/packages/tpetry/laravel-mysql-explain)[ Docs](https://github.com/tpetry/laravel-mysql-explain)[ RSS](/packages/tpetry-laravel-mysql-explain/feed)WikiDiscussions main Synced 3d ago

READMEChangelogDependencies (20)Versions (13)Used By (0)

Laravel MySQL Visual Explains
=============================

[](#laravel-mysql-visual-explains)

[![License](https://camo.githubusercontent.com/3498ae7d3cd7ed4b9232a34300426edee4230dc37495f806a87e6afb7e517703/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7470657472792f6c61726176656c2d6d7973716c2d6578706c61696e3f636f6c6f723d626c7565266c6162656c3d4c6963656e7365)](https://camo.githubusercontent.com/3498ae7d3cd7ed4b9232a34300426edee4230dc37495f806a87e6afb7e517703/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7470657472792f6c61726176656c2d6d7973716c2d6578706c61696e3f636f6c6f723d626c7565266c6162656c3d4c6963656e7365)[![PHP](https://camo.githubusercontent.com/d46341f71073696d161cde27b39c0c2b7e27edd3ba0abdc087a8192dc6148b1e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7470657472792f6c61726176656c2d6d7973716c2d6578706c61696e3f636f6c6f723d626c7565266c6162656c3d504850)](https://camo.githubusercontent.com/d46341f71073696d161cde27b39c0c2b7e27edd3ba0abdc087a8192dc6148b1e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7470657472792f6c61726176656c2d6d7973716c2d6578706c61696e3f636f6c6f723d626c7565266c6162656c3d504850)[![Laravel](https://camo.githubusercontent.com/b5225dc351d8e2df8a199b07059e043ba369b70cb2b1e0729bd11e13cc254c27/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d362e2a2d2d31312e2a2d626c7565)](https://camo.githubusercontent.com/b5225dc351d8e2df8a199b07059e043ba369b70cb2b1e0729bd11e13cc254c27/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d362e2a2d2d31312e2a2d626c7565)[![Latest Version on Packagist](https://camo.githubusercontent.com/e254f4e47d15c1aaa6d9e747ca83130e114e4a93a3bb213c534b08d16ce13c17/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7470657472792f6c61726176656c2d6d7973716c2d6578706c61696e2e7376673f6c6162656c3d5061636b6167697374)](https://packagist.org/packages/tpetry/laravel-mysql-explain)[![GitHub Unit Tests Action Status](https://camo.githubusercontent.com/39064df43f965f1d1e2f2753316eb9e26928e4200499156e32cd4197f655d9e2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7470657472792f6c61726176656c2d6d7973716c2d6578706c61696e2f756e69742d74657374732e796d6c3f6c6162656c3d5465737473)](https://github.com/tpetry/laravel-mysql-explain/actions/workflows/unit-tests.yml)[![GitHub Static Analysis Action Status](https://camo.githubusercontent.com/5254b04ea2575b84efd47eda9f1929b45dbcd0f718b5eb866f25d82dba515297/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7470657472792f6c61726176656c2d6d7973716c2d6578706c61696e2f7374617469632d616e616c797369732e796d6c3f6c6162656c3d537461746963253230416e616c79736973)](https://github.com/tpetry/laravel-mysql-explain/actions/workflows/static-analysis.yml)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/f55d309277c341bd41b3b4c1a77375111067677de44e29590f58c10eee891d8b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7470657472792f6c61726176656c2d6d7973716c2d6578706c61696e2f636f64652d7374796c652e796d6c3f6c6162656c3d436f64652532305374796c65)](https://github.com/tpetry/laravel-mysql-explain/actions/workflows/code-style.yml)

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](https://mysqlexplain.com) and transformed to be much easier to understand.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require tpetry/laravel-mysql-explain
```

Usage
-----

[](#usage)

### Query Builder

[](#query-builder)

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

TypeAction`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

[](#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
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Credits
-------

[](#credits)

- [Tobias Petry](https://github.com/tpetry)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

54

—

FairBetter than 96% of packages

Maintenance78

Regular maintenance activity

Popularity51

Moderate usage in the ecosystem

Community14

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~100 days

Recently: every ~152 days

Total

11

Last Release

114d ago

Major Versions

1.3.2 → 2.0.02024-09-27

### Community

Maintainers

![](https://www.gravatar.com/avatar/ccc334e20491a79e2d81037803a4c96fe45dc2b0f721c631ab23e390242383b0?d=identicon)[tpetry](/maintainers/tpetry)

---

Top Contributors

[![tpetry](https://avatars.githubusercontent.com/u/315686?v=4)](https://github.com/tpetry "tpetry (47 commits)")[![G3z](https://avatars.githubusercontent.com/u/875086?v=4)](https://github.com/G3z "G3z (1 commits)")[![hungthai1401](https://avatars.githubusercontent.com/u/22017922?v=4)](https://github.com/hungthai1401 "hungthai1401 (1 commits)")

---

Tags

explainlaravelmysqlquery-optimizationlaravelmysqlexplain

### Embed Badge

![Health badge](/badges/tpetry-laravel-mysql-explain/health.svg)

```
[![Health](https://phpackages.com/badges/tpetry-laravel-mysql-explain/health.svg)](https://phpackages.com/packages/tpetry-laravel-mysql-explain)
```

###  Alternatives

[laravel/socialite

Laravel wrapper around OAuth 1 &amp; OAuth 2 libraries.

5.7k108.5M887](/packages/laravel-socialite)[illuminate/database

The Illuminate Database package.

2.8k54.9M11.7k](/packages/illuminate-database)[laravel/boost

Laravel Boost accelerates AI-assisted development by providing the essential context and structure that AI needs to generate high-quality, Laravel-specific code.

3.5k21.5M600](/packages/laravel-boost)[spatie/laravel-health

Monitor the health of a Laravel application

87512.0M167](/packages/spatie-laravel-health)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M131](/packages/roots-acorn)[nativephp/mobile

NativePHP for Mobile

1.1k75.1k95](/packages/nativephp-mobile)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
