Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我导入索引时,一切正常(包括关系)。
问题是主模型不监视关系。
当我更新关系时,索引也不会更新。
有没有办法在Cache::tags修改关系时使用类似的东西来更新索引?或者也许是另一种方式。
Cache::tags
不幸的是,使用 Scout 没有直接的方法可以做到这一点。但是,使用 Laravel 的另一个功能,您可以“欺骗” Laravel 更新记录。
$touches向每个包含与父级关系的方法名称的子类添加一个变量。例如,如果您有一个带有post()返回belongsTo()关系的方法的 Comment 类,您将添加到 Comment 类中:
$touches
post()
belongsTo()
protected $touches = ['post'];
当评论被修改时,它会更新updated_at父级的字段,Scout 会看到并更新记录。
updated_at