vpominchuk/laravel-mysql-use-index-scope

A super simple package allowing for use MySQL `USE INDEX` and `FORCE INDEX` statements
612,169 41
Install
composer require vpominchuk/laravel-mysql-use-index-scope
Latest Version:v1.0.8
PHP:^7.4|^8.0
Laravel:6 – 12
License:MIT
Last Updated:Nov 24, 2025
Links: GitHub  ·  Packagist
Maintainer: vpominchuk

Latest Version on Packagist Software License Total Downloads

Laravel MySQL Use Index Scope

A super simple package allowing for use MySQL USE INDEX and FORCE INDEX statements.

Requirements

  • PHP ^7.4 | ^8.0
  • Laravel 6, 7, 8, 9, 10, 11, and 12

Installation

composer require vpominchuk/laravel-mysql-use-index-scope

Usage

Simply reference the required trait in your model:

Model:

    use VPominchuk\ModelUseIndex;
    
    class MyModel extends Model
    {
        use ModelUseIndex;
    }

Anywhere in the code:

    $builder = MyModel::where('name', $name)->where('age', $age)->
        useIndex($indexName)->...

Database table structure:

You need to create a named index with required name. For example:

Laravel Migration:

    $table->index(['name', 'age'], 'user_age_index');

Available methods

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.

Security

If you discover any security related issues, please use the issue tracker.

Credits

License

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

Related Packages

shaburov/laravel-mysql-index-hints-scope

Index Hints for laravel https://dev.mysql.com/doc/refman/5.7/en/index-hints.html

65,079 5
doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

641,106,524 9,700
laravel/framework

The Laravel Framework.

593,882,149 34,959
laravel/tinker

Powerful REPL for the Laravel framework.

502,645,077 7,441
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

418,291,778 609

Version History

Version Released PHP Laravel License
v1.0.8 ^7.4|^8.0 ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0 MIT
v1.0.7 ^7.4|^8.0 ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0 MIT
v1.0.6 ^7.4 | ^8.0 ^6.0|^7.0|^8.0|^9.0|^10.0 MIT
v1.0.4 ^7.4 | ^8.0 ^6.0|^7.0|^8.0|^9.0 MIT
v1.0.3 ^7.4 | ^8.0 ^6.0|^7.0|^8.0|^9.0 MIT