我正在使用 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/