Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use with DB:: #1

Open
omidMolaverdi opened this issue Nov 21, 2021 · 1 comment
Open

use with DB:: #1

omidMolaverdi opened this issue Nov 21, 2021 · 1 comment

Comments

@omidMolaverdi
Copy link

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);

@tylerwiegand
Copy link

@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;
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants