ModelObserver
class ModelObserver
Observer that handles search index updates for Eloquent models.
Listens to model events (saved, deleted, forceDeleted, restored) and updates the search index accordingly. Supports soft deletes and transaction-aware event dispatching.
Constants
| protected SYNCING_DISABLED_CONTEXT_KEY_PREFIX |
Context key prefix for storing whether syncing is disabled per model class. |
| protected FORCE_SAVING_CONTEXT_KEY |
Context key for storing whether the current coroutine is forcing a search update. |
Properties
| bool | $afterCommit | Indicates if Scout will dispatch the observer's events after all database transactions have committed. |
|
| protected bool | $usingSoftDeletes | Indicates if Scout will keep soft deleted records in the search indexes. |
Methods
Create a new observer instance.
Enable syncing for the given class.
Disable syncing for the given class.
Determine if syncing is disabled for the given class or model.
Details
at line 46
__construct()
Create a new observer instance.
at line 59
static void
enableSyncingFor(string $class)
Enable syncing for the given class.
Uses Context for coroutine-safe state management.
at line 71
static void
disableSyncingFor(string $class)
Disable syncing for the given class.
Uses Context for coroutine-safe state management.
at line 83
static bool
syncingDisabledFor(object|string $class)
Determine if syncing is disabled for the given class or model.
Uses Context for coroutine-safe state management.
at line 95
void
saved(Model $model)
Handle the saved event for the model.
at line 125
void
deleted(Model $model)
Handle the deleted event for the model.
at line 150
void
forceDeleted(Model $model)
Handle the force deleted event for the model.
at line 164
void
restored(Model $model)
Handle the restored event for the model.
at line 174
protected mixed
whileForcingUpdate(Closure $callback)
Execute the given callback while forcing updates.
at line 189
protected bool
usesSoftDelete(Model $model)
Determine if the given model uses soft deletes.