Package

Vpominchuk Laravel Mysql Use Index Scope

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

Package

vpominchuk/laravel-mysql-use-index-scope

View on GitHub →

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 and 10

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.

Vpominchuk Laravel Mysql Use Index Scope Related Articles

Learn to master Query Scopes in Laravel image

Learn to master Query Scopes in Laravel

Read article
How to fix "SQLSTATE[HY000] [2002] Connection refused" Laravel error in GitHub Actions image

How to fix "SQLSTATE[HY000] [2002] Connection refused" Laravel error in GitHub Actions

Read article
Laravel and MySQL 8: Fixing MySQL Server Has Gone Away Error image

Laravel and MySQL 8: Fixing MySQL Server Has Gone Away Error

Read article
The Hidden Cost of MySQL Defaults in Laravel Apps image

The Hidden Cost of MySQL Defaults in Laravel Apps

Read article
Laravel Deadlocks: Causes and Fixes image

Laravel Deadlocks: Causes and Fixes

Read article
Enhancing Laravel Queries with Reusable Scope Patterns image

Enhancing Laravel Queries with Reusable Scope Patterns

Read article

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm

Let your users buy domains without leaving your app

If your Laravel app gives users a site, a storefront, or a workspace, they’ll eventually want their own domain. The name.com API lets them search, register, and connect one without leaving your product. It’s a clean REST API, so Laravel’s HTTP client is all you need.

Let your users buy domains without leaving your app

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift