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

Overriding model sync on save #19

Open
jamesgraham opened this issue May 12, 2020 · 1 comment
Open

Overriding model sync on save #19

jamesgraham opened this issue May 12, 2020 · 1 comment

Comments

@jamesgraham
Copy link

In some cases, we might save a model but not wish to sync it to ES.

For example, if we are updating an attribute that is not indexed, this creates an unnecessary overhead.

Is there a preferred method to achieve this?

@michaeljennings
Copy link
Owner

The model syncs to ES using the laravel model events

When you implement the Michaeljennings\Laralastica\Searchable trait it adds a bootSearchable method which registers a model observer, if you comment that out it will stop it syncing every time.

protected static function bootSearchable()
{
    // if ( ! is_null(static::$dispatcher)) {
    //     static::observe(new Observer(static::$dispatcher));
    // }
}

Then you can manually fire the Michaeljennings\Laralastica\Events\IndexesWhenSaved event whenever you want to index your model.

Alternatively, if you only want to index a model when certain criteria have been met you could extend the Michaeljennings\Laralastica\Observer class and override the bootSearchable method to use your new observer. Then you could perform the relevant logic checks in the observer.

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