Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Missing ability to disable global scope when searching #17

Open
mbardelmeijer opened this issue Jan 10, 2017 · 1 comment
Open

Missing ability to disable global scope when searching #17

mbardelmeijer opened this issue Jan 10, 2017 · 1 comment

Comments

@mbardelmeijer
Copy link
Contributor

When using global scopes, in my case based on user permission, and you want to disable those scopes for fetching, normally you can do something like:

$users = User::withoutGlobalScope(UserScope::class)->get();

When searching, it isn't possible to pass custom calls to the MySQL engine. A (very very very) ugly workaround is to overwrite the search method to disable scopes before passing the model to the engine:

public static function search(string $query, $callback = null): Collection
{
        // Temporary disable global scopes
        static::$globalScopes = [];
        $results = (new ScoutBuilder(new static(), $query, $callback))->get();
        static::addGlobalScope(new UserScope());
        return $results;
}

Any other ideas how to resolve this in a more elegant way?

@sunilbfcj1234
Copy link

Hi! @mbardelmeijer
Have you got any solution?

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

No branches or pull requests

2 participants