Laravel Mysql Use Index Scope

vpominchuk/laravel-mysql-use-index-scope image

Laravel Mysql Use Index Scope stats

Downloads
210.5K
Stars
34
Open Issues
1
Forks
3

View on GitHub →

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

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 photo

Software engineer at Haigh Consultancy Services.

Photography as a hobby.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Vpominchuk Laravel Mysql Use Index Scope Related Articles

Streamed JSON Responses Added to Laravel 10.43 image

Streamed JSON Responses Added to Laravel 10.43

Read article
Acquaint Softtech logo

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
Statamic logo

Statamic

The drop-in ready Laravel CMS you’re been waiting for. Go full-stack or headless, flat file or database – it’s up to you.

Statamic
The Certification of Competence for Laravel logo

The Certification of Competence for Laravel

A community-driven, proctored assessment across 4 levels designed to validate real-world Laravel knowledge, from Junior to mastery-level Artisan. Official Vue.js, Official Nuxt, Angular, React, JS certifications also available.

The Certification of Competence for Laravel
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $9500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
LoadForge logo

LoadForge

Scalable load testing for web apps & APIs. Simulate real-world traffic and identify breaking points and performance limits with powerful, scalable load tests designed for Laravel.

LoadForge
PhpStorm logo

PhpStorm

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

PhpStorm