PHPackages                             sagar-s-bhedodkar/laravel-index-advisor - 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. sagar-s-bhedodkar/laravel-index-advisor

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

sagar-s-bhedodkar/laravel-index-advisor
=======================================

Monitor Eloquent/DB queries in your Laravel application and suggest scaffold migrations for missing indexes.

1.0.0(6mo ago)05MITPHPPHP ^8.1

Since Oct 18Pushed 6mo agoCompare

[ Source](https://github.com/sagar-s-bhedodkar/laravel-index-advisor)[ Packagist](https://packagist.org/packages/sagar-s-bhedodkar/laravel-index-advisor)[ RSS](/packages/sagar-s-bhedodkar-laravel-index-advisor/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

🧱 Laravel Index Advisor
=======================

[](#-laravel-index-advisor)

> **Monitor your Eloquent/DB queries in Laravel and get actionable index suggestions to optimize performance.**

[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](LICENSE)[![Laravel](https://camo.githubusercontent.com/73692ab0f1fac2901149539199fa738ac249d6cd2387048e8063666cfab3d736/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31302e7825323025374325323031312e7825323025374325323031322e782d7265642e737667)](https://laravel.com)[![Packagist](https://camo.githubusercontent.com/9442eaa3645acd89c94e47bf0d896192e16096bf3315a6987e8325070e3b7d8f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73616761722d732d626865646f646b61722f6c61726176656c2d696e6465782d61647669736f722e737667)](https://packagist.org/packages/sagar-s-bhedodkar/laravel-index-advisor)

---

📘 Table of Contents
-------------------

[](#-table-of-contents)

- [Introduction](#-introduction)
- [Features](#-features)
- [Installation](#-installation)
- [Configuration](#-configuration)
- [Usage](#-usage)
- [Artisan Commands](#-artisan-commands)
- [Contributing](#-contributing)
- [License](#-license)
- [Author](#-author)

---

🚀 Introduction
--------------

[](#-introduction)

**Laravel Index Advisor** is a Laravel package that **monitors your database queries** and provides **intelligent suggestions for missing indexes**. It helps developers identify slow or frequently-used queries and optimize database performance with actionable recommendations.

---

✨ Features
----------

[](#-features)

- 📊 Tracks Eloquent and DB queries automatically
- ⏱️ Detects slow queries using a configurable threshold
- 🛠️ Suggests indexes for columns used in WHERE clauses
- 💾 Caches queries to analyze repeated usage
- 🔄 Optional migration generation for suggested indexes
- ⚙️ Artisan commands for query management
- ✅ Production-ready and configurable

---

⚙️ Installation
---------------

[](#️-installation)

Require the package via Composer:

```
composer require sagar-s-bhedodkar/laravel-index-advisor:@dev
```

The package **auto-discovers** itself; no manual registration is required.

Publish the configuration file (optional):

```
php artisan vendor:publish --tag=config
```

---

🛠 Configuration
---------------

[](#-configuration)

The configuration file `config/index-advisor.php` allows you to customize the behavior:

```
return [
    'enabled' => true,
    'slow_query_threshold_ms' => 200,
    'ignore_tables' => ['migrations', 'jobs', 'failed_jobs'],
    'ignore_columns' => ['id', 'created_at', 'updated_at'],
    'cache_key' => 'index_advisor:queries',
    'cache_ttl' => 86400,
    'max_storage' => 1000,
    'usage_threshold' => 5,
    'auto_generate_migrations' => false,
    'cache_driver' => 'file',
    'min_rows' => 50,
];
```

- `slow_query_threshold_ms`: Threshold for marking a query as slow
- `usage_threshold`: Number of times a column must be used to trigger an index suggestion
- `auto_generate_migrations`: If `true`, automatically generate migration stubs for missing indexes

---

🧠 Usage
-------

[](#-usage)

### Record Queries

[](#record-queries)

Laravel Index Advisor automatically records queries during runtime.

### Analyze Queries

[](#analyze-queries)

To get index suggestions:

```
use SagarSBhedodkar\IndexAdvisor\Facades\IndexAdvisor;

$suggestions = IndexAdvisor::analyse();
return response()->json($suggestions);
```

### Generate Migration Stub

[](#generate-migration-stub)

```
$stub = IndexAdvisor::generateMigrationStub($suggestions);
file_put_contents(database_path('migrations/' . now()->format('Y_m_d_His') . '_add_indexes.php'), $stub);
```

### Clear Stored Queries

[](#clear-stored-queries)

```
IndexAdvisor::clearStored();
```

---

🧰 Artisan Commands
------------------

[](#-artisan-commands)

- `php artisan index-advisor:generate-migration` — Generate a migration for suggested indexes
- Additional commands may be added for managing cache and recorded queries

---

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome!

1. Fork the repository
2. Create a feature branch: `git checkout -b feature/new-feature`
3. Commit your changes: `git commit -m "Add new feature"`
4. Push to your fork: `git push origin feature/new-feature`
5. Submit a Pull Request 🎉

---

📄 License
---------

[](#-license)

This package is open-sourced software licensed under the **MIT license**.

---

👨‍💻 Author
----------

[](#‍-author)

**Sagar Sunil Bhedodkar**📧 🌐 [GitHub Profile](https://github.com/sagar-s-bhedodkar)

---

> Made with ❤️ for Laravel developers who want actionable index suggestions and optimized database performance.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance66

Regular maintenance activity

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

206d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2f14a63a25120de3ec7ce2eff77be8ba80345f1de81a84ceaa719ae9d1534687?d=identicon)[sbsagar](/maintainers/sbsagar)

---

Top Contributors

[![sbsaga](https://avatars.githubusercontent.com/u/110087468?v=4)](https://github.com/sbsaga "sbsaga (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sagar-s-bhedodkar-laravel-index-advisor/health.svg)

```
[![Health](https://phpackages.com/badges/sagar-s-bhedodkar-laravel-index-advisor/health.svg)](https://phpackages.com/packages/sagar-s-bhedodkar-laravel-index-advisor)
```

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[genealabs/laravel-pivot-events

This package introduces new eloquent events for sync(), attach(), detach() or updateExistingPivot() methods on BelongsToMany relation.

1404.9M8](/packages/genealabs-laravel-pivot-events)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)

PHPackages © 2026

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