Laravel MySQL Advisor is a read-only health advisor for the MySQL or MariaDB behind a Laravel app. It reports unused, duplicate and missing indexes, full table scans, N+1 patterns and server pressure, and shows the SQL or migration that fixes each one [1].

The problem

MySQL keeps most of this information in performance_schema and information_schema [1], but nothing in a Laravel app reads it for you. db:show lists sizes and db:monitor counts connections; neither says which index to drop. Two blind spots stand out:

  • foreignId('user_id') without ->constrained() creates no index.
  • An N+1 never shows in a slow-query log: it is one fast query run thousands of times.

How it works

composer require amjadiqbal/laravel-mysql-advisor php artisan mysql-advisor:report 

Each finding has a severity (critical, warning or notice), the numbers behind it and, where it applies, the fix as SQL and as a Laravel migration. Unused-index fixes come in two steps: hide the index first (INVISIBLE on MySQL [2]), then drop it.

What it checks

  • Indexes: unused, redundant, unindexed foreign key
  • Queries: full table scan, top statements, N+1
  • Tables: missing primary key, size, fragmentation, stale statistics
  • Server: buffer pool hit ratio, disk temp tables, connection headroom

Safety and limits

  • Every statement is a SELECT or SHOW.
  • The dashboard returns 403 outside the local environment until you define the viewMysqlAdvisor gate [3].
  • Checks that cannot run are listed as skipped with the reason, never as a clean result.
  • Counters restart with the server, so unused indexes stay notices until 7 days of uptime.

The report exits 1 when a finding reaches --fail-on, so it can run in CI as an artisan command [4]. Requires PHP 8.3+, Laravel 12 or 13, MySQL 8.0+ or MariaDB 10.6+. MIT licensed.

Docs and demo: urlshortly.com/NOPFg. Source: urlshortly.com/iPxco.

References

  1. MySQL: Performance Schema
  2. MySQL: Invisible Indexes
  3. Laravel: Authorization
  4. Laravel: Artisan Console