更新索引算法
Update index algolia
我正在 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索引中的用户。任何想法如何进行?
我相信您可以为此使用 searchable() 方法。在 $this->update()
之后你会得到类似的东西:
App\Documents::where('user_id', '=', $this->id)->searchable();
请让我知道这是否有效,或者我是否遗漏了什么。
我正在 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索引中的用户。任何想法如何进行?
我相信您可以为此使用 searchable() 方法。在 $this->update()
之后你会得到类似的东西:
App\Documents::where('user_id', '=', $this->id)->searchable();
请让我知道这是否有效,或者我是否遗漏了什么。