|
1 | | -# laravel-mysql-use-index-scope |
2 | | -A super simple package allowing for use MySQL 'USE INDEX' and 'FORCE INDEX' statements. |
| 1 | + |
| 2 | +# Laravel MySQL Use Index Scope |
| 3 | +A super simple package allowing for use MySQL `USE INDEX` and `FORCE INDEX` statements. |
| 4 | + |
| 5 | +## Requirements |
| 6 | +- PHP `^7.4 | ^8.0` |
| 7 | +- Laravel 6, 7 and 8 |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +`composer require vpominchuk/laravel-mysql-use-index-scope` |
| 12 | + |
| 13 | +## Usage |
| 14 | +Simply reference the required trait in your model: |
| 15 | + |
| 16 | +### Model: |
| 17 | +```php |
| 18 | + use VPominchuk\ModelUseIndex; |
| 19 | + |
| 20 | + class MyModel extends Model |
| 21 | + { |
| 22 | + use ModelUseIndex; |
| 23 | + } |
| 24 | +``` |
| 25 | + |
| 26 | +### Anywhere in the code: |
| 27 | +```php |
| 28 | + $builder = MyModel::where('name', $name)->where('age', $age)-> |
| 29 | + useIndex($indexName)->... |
| 30 | +``` |
| 31 | + |
| 32 | +### Database table structure: |
| 33 | +You need to create a named index with required name. For example: |
| 34 | + |
| 35 | +Laravel Migration: |
| 36 | +```php |
| 37 | + $table->index(['name', 'age'], 'user_age_index'); |
| 38 | +``` |
| 39 | +## Available methods |
| 40 | +#### `useIndex($indexName)` |
| 41 | +Tells MySQL to use an index if it possible. |
| 42 | + |
| 43 | +#### `forceIndex($indexName)` |
| 44 | +Force MySQL to use an index if it possible. |
| 45 | + |
| 46 | +## Security |
| 47 | + |
| 48 | +If you discover any security related issues, please use the issue tracker. |
| 49 | + |
| 50 | +## Credits |
| 51 | + |
| 52 | +- [Vasyl Pominchuk](https://github.com/vpominchuk) |
| 53 | + |
| 54 | +## License |
| 55 | + |
| 56 | +The MIT License (MIT). Please see [License File](LICENSE) for more information. |
| 57 | + |
0 commit comments