When I import the index everything works fine (including relations).
The problem is that the main model does not watch over relations.
When I update a relation, the index is not updated too.
Is there any way to use something similar with Cache::tags
to update the index when a relation is modified? Or maybe is another way.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With