laravel - 更新索引算法

标签 laravel laravel-5 algolia laravel-scout

我正在使用 Laravel 5.5 和 Scout。我在 algolia 中有一个使用文档的索引以及与这些文档关联的用户

class Documents extends Model
{
    use Searchable;

    public function toSearchableArray()
    {
      $data = $this->toArray();

      // formatting relationship for algolia

      $data['users'] = $this->types->toArray();
      $data['document_type'] = $this->typeDocuments->name;
      return $data;
    }

    protected $fillable = array('name', 'description', 'document_type');

    public function types() {
        return $this->belongsToMany('App\Users', 'document_rights', 'user_id', 'id');
    }

    public function typeDocuments() {
        return $this->belongsTo('App\Document_type', 'document_type');
    }
}

就我而言,有一天我会更新用户的名称,如下所示:

public function update(Request $request)
{
    $user = Users::find(5);
    $user->name = 'jean floriot';
    $user->update();
}

但它永远不会改变 Algolia 索引中的 User。有什么想法如何继续吗?

最佳答案

我相信您可以使用 searchable() 方法来实现这一点。在 $this->update() 之后你会得到类似:

App\Documents::where('user_id', '=', $this->id)->searchable();

请告诉我这是否有效或者我是否遗漏了某些内容。

关于laravel - 更新索引算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46180552/

相关文章:

javascript - Algolia:使用 AND 子句在每个字段中搜索多个值

php - Laravel 5 邮件队列不工作

php - 无法在 Laravel 4 中设置缓存控制

php - Laravel Mail::queue 错误:闭包序列化失败,即使是最基本的用法

javascript - VueJs 动态 v-on 事件可能吗?

php - 使用 Pgsql 驱动程序从 Laravel 5 连接到 Redshift 数据库?

android - 使用 Android 的 Algolia 和 Cloud Firestore?

php - Laravel 和时间戳 - 它总是日期列吗?

php - Laravel:具有多对多关系的历史排名系统

facet - Algolia facet 按空/空值过滤