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

Tighten

We help companies turn great ideas into amazing apps, products, and services.

Tighten
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
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
Blastup logo

Blastup

Blastup provides social media enhancement services including buying Instagram likes, followers, and views, with features like instant delivery and a variety of packages to suit different needs.

Blastup
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Typesense Search logo

Typesense Search

Typesense is an open source, blazing-fast search engine, optimized for helping you build delightful search experiences for your sites and apps. Natively integrated with Laravel Scout.

Typesense Search