PHPackages                             ashokdevatwal/laravel-smart-db-optimizer - 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. ashokdevatwal/laravel-smart-db-optimizer

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

ashokdevatwal/laravel-smart-db-optimizer
========================================

Laravel Smart Database Optimizer is a package designed to help developers identify slow queries, suggest optimizations, and recommend indexes to improve database performance.

v1.0.0(1y ago)010MITPHPPHP &gt;=7.4CI failing

Since Mar 8Pushed 1y ago1 watchersCompare

[ Source](https://github.com/ars-technology-india/laravel-smart-db-optimizer)[ Packagist](https://packagist.org/packages/ashokdevatwal/laravel-smart-db-optimizer)[ RSS](/packages/ashokdevatwal-laravel-smart-db-optimizer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Laravel Smart Database Optimizer
================================

[](#laravel-smart-database-optimizer)

[![Latest Version](https://camo.githubusercontent.com/849aaaf2089c9693018b4ad887c3d207d9d433e22927fd8b257325c39834b308/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6173686f6b646576617477616c2f6c61726176656c2d736d6172742d64622d6f7074696d697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ashokdevatwal/laravel-smart-db-optimizer)[![Total Downloads](https://camo.githubusercontent.com/be0e037eaddd7f5770c55a065012b7a11407f6740cce8f77c40ac0cd3a6c36de/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6173686f6b646576617477616c2f6c61726176656c2d736d6172742d64622d6f7074696d697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ashokdevatwal/laravel-smart-db-optimizer)[![License](https://camo.githubusercontent.com/a167c64d78314031d3e95b6c758cd509b5c0f227f7e6c3ba4c72e0f0f81cb1f7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6172732d746563686e6f6c6f67792d696e6469612f6c61726176656c2d736d6172742d64622d6f7074696d697a65722e7376673f7374796c653d666c61742d737175617265)](LICENSE)

**Laravel Smart Database Optimizer** is a package designed to help developers identify slow queries, suggest optimizations, and recommend indexes to improve database performance.

---

🚀 Features
----------

[](#-features)

- ✅ Logs slow queries automatically
- ✅ Provides CLI commands for analysis
- ✅ Suggests indexes based on query patterns
- ✅ Includes middleware for real-time query tracking
- ✅ Simple installation and configuration

---

📦 Installation
--------------

[](#-installation)

### Step 1: Install via Composer

[](#step-1-install-via-composer)

```
composer require ashokdevatwal/laravel-smart-db-optimizer
```

### Step 2: Publish Configurations

[](#step-2-publish-configurations)

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

### Step 3: Run Migrations

[](#step-3-run-migrations)

```
php artisan migrate
```

### Step 4: Add Middleware (Optional)

[](#step-4-add-middleware-optional)

If you want to log queries globally, add this to your `app/Http/Kernel.php` file:

```
protected $middleware = [
    \AshokDevatwal\SmartDbOptimizer\Middleware\QueryLogger::class,
];
```

---

⚡ Usage
-------

[](#-usage)

### Analyze Slow Queries

[](#analyze-slow-queries)

Run the following command to analyze slow queries:

```
php artisan smartdb:analyze
```

### Suggest Indexes

[](#suggest-indexes)

Run the command to get index recommendations:

```
php artisan smartdb:suggest-indexes
```

### Detect Frequent Queries &amp; Suggested Caching

[](#detect-frequent-queries--suggested-caching)

```
php artisan smartdb:detect-frequent
```

### Automatically Cache Queries

[](#automatically-cache-queries)

If auto\_cache is `enabled`, frequently executed queries will be automatically cached.

### View Logged Queries via API

[](#view-logged-queries-via-api)

You can fetch logged queries using:

```
GET /smartdb/queries

```

---

⚙️ Configuration
----------------

[](#️-configuration)

Edit `config/smartdb.php` to set the slow query threshold (default: 100ms):

```
return [
    'slow_query_threshold' => 100, // Queries taking more than 100ms
    'frequent_query_threshold' => 5, // Number of times a query runs in short time to be flagged
    'frequent_query_time_window' => 60, // Time window in seconds to track repeated queries
    'auto_cache' => true, // Enable or disable automatic caching of frequent queries
];
```

---

🛠 Troubleshooting
-----------------

[](#-troubleshooting)

### Query Logs Table Not Found?

[](#query-logs-table-not-found)

Run migrations again:

```
php artisan migrate
```

### Middleware Not Working?

[](#middleware-not-working)

Ensure it's registered in `app/Http/Kernel.php`.

---

📜 License
---------

[](#-license)

This package is open-source and available under the MIT license.

---

💡 Future Enhancements
---------------------

[](#-future-enhancements)

- UI Dashboard for Query Analysis
- AI-powered Index Suggestions
- Support for Multiple Databases

🚀 Contributions are welcome! Feel free to submit pull requests or open issues.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance45

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 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

428d ago

### Community

Maintainers

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

---

Top Contributors

[![ashokdevatwal](https://avatars.githubusercontent.com/u/18355852?v=4)](https://github.com/ashokdevatwal "ashokdevatwal (43 commits)")

---

Tags

laraveldboptimizer

### Embed Badge

![Health badge](/badges/ashokdevatwal-laravel-smart-db-optimizer/health.svg)

```
[![Health](https://phpackages.com/badges/ashokdevatwal-laravel-smart-db-optimizer/health.svg)](https://phpackages.com/packages/ashokdevatwal-laravel-smart-db-optimizer)
```

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[dragon-code/laravel-deploy-operations

Performing any actions during the deployment process

240173.5k2](/packages/dragon-code-laravel-deploy-operations)[cybercog/laravel-clickhouse

ClickHouse migrations for Laravel

163166.8k](/packages/cybercog-laravel-clickhouse)[stayallive/laravel-eloquent-observable

Register Eloquent model event listeners just-in-time directly from the model.

2928.9k7](/packages/stayallive-laravel-eloquent-observable)

PHPackages © 2026

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