2

我将 Laravel 5.5 与 Scout 一起使用。我在 algolia 中有一个使用 Documents 的索引以及与这些 Documents 关联的用户

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 索引中的用户。任何想法如何进行?

4

1 回答 1

5

I believe you can use the searchable() method for that. After $this->update() you will get something like:

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

Please let me know if that worked or if I missed something.

于 2017-09-14T09:53:28.373 回答