laravel-mysql-use-index-scope
laravel-mysql-use-index-scope copied to clipboard
use with DB::
Thanks for the great work.
Is there any way to change this package to work with the DB:: query builder? for example the query below:
DB::select("select name from users USE INDEX (names) limit 10");
being written like:
DB::table('users')->select('name')->useIndex('names')->limit(10);
@omidMolaverdi put this in your AppServiceProvider to use it anywhere 👍
Builder::macro('useIndex', function (string $indexName) {
$tableName = $this->getQuery()->from;
$this->getQuery()->from(\DB::raw("{$tableName} USE INDEX ({$indexName})"));
return $this;
});