Get Visual MySQL EXPLAIN for Laravel.

1.3.1 2024-07-13 10:09 UTC

This package is auto-updated.

Last update: 2024-07-13 10:09:42 UTC


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 and transformed to be much easier to understand.


You can install the package via composer:

composer require tpetry/laravel-mysql-explain


Query Builder

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

// $url will be e.g.
$url = Film::where('description', 'like', '%astronaut%')

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

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

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\MysqlExplain\Facades\MysqlExplain;

// $url will be e.g.
$url = MysqlExplain::submitQuery(
    'SELECT * FROM actor WHERE first_name = ?',


composer test


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



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