Laravel Scout - observe relations Laravel Scout - observe relations elasticsearch elasticsearch

Laravel Scout - observe relations


There is, unfortunately, no direct way to do this using Scout. However, using another Laravel feature you can 'trick' Laravel into updating the record.

Add a $touches variable to each of the child classes containing the method names of the relationship to the parent. For example, if you had a Comment class with a post() method returning the belongsTo() relationship, you'd add to the Comment class:

protected $touches = ['post'];

When a comment is modified, it will update the updated_at field of the parent, which Scout will see and update the record.