A super simple package allowing for use MySQL `USE INDEX` and `FORCE INDEX` statements
vpominchuk/laravel-mysql-use-index-scope is a Laravel package for a super simple package allowing for use mysql `use index` and `force index` statements.
It currently has 41 GitHub stars and 592.954 downloads on Packagist (latest version v1.0.8).
Install it with composer require vpominchuk/laravel-mysql-use-index-scope.
Discover more Laravel packages by vpominchuk
or browse all Laravel packages to compare alternatives.
Last updated

A super simple package allowing for use MySQL USE INDEX and FORCE INDEX statements.
^7.4 | ^8.0composer require vpominchuk/laravel-mysql-use-index-scope
Simply reference the required trait in your model:
use VPominchuk\ModelUseIndex;
class MyModel extends Model
{
use ModelUseIndex;
}
$builder = MyModel::where('name', $name)->where('age', $age)->
useIndex($indexName)->...
You need to create a named index with required name. For example:
Laravel Migration:
$table->index(['name', 'age'], 'user_age_index');
useIndex($indexName)Tells MySQL to use an index if it possible.
forceIndex($indexName)Force MySQL to use an index if it possible.
ignoreIndex($indexName)Ask MySQL to ignore an index if it possible.
If you discover any security related issues, please use the issue tracker.
The MIT License (MIT). Please see License File for more information.