Try Depot: Bring ultra-fast, remote Docker builds directly to your Laravel workflow

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.


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

Shift

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

Shift
Harpoon: Next generation time tracking and invoicing logo

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
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
PhpStorm logo

PhpStorm

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

PhpStorm