Algolia 记录正在更新错误的数据类型

Aloglia records are updating with wrong datatypes

我在 algolia 记录中遇到了一些问题。我 People table 中有一些属性(例如 id(int), user_id(int), name(varchar) ... 等)。

当我通过 Laravel 5.5 将新记录添加到数据库时,algolia 一切正常,但我尝试更新记录,尽管记录正在完美更新,但数据类型正在改变。就像之前更新记录 user_id 是 int = 6 在更新名称或其他内容之后 user_id 正在隐式转换为 varchar。

我不知道发生了什么。

更新此记录之前:

更新同一条记录后:

插入代码为:

 $new_person = People::create([
            'user_id' => Auth::user()->id,
            'stage_id' => 0,
            'source_id' => 0,
            'agent_id' => 0,
            'custom_field_id' => 0,
            'fname' => $request->first_name,
            'lname' => $request->last_name,
            'phone' => $request->phone,
            'email' => $request->email,
            'avatar' => "/images/user.png",
            'name_slug' => createPeopleSlug($request->first_name , $request->last_name)
        ]);

更新代码为:

$person = People::find($request->personID);
            $person->tags = $tagsString;
            $person->save();

我不是 Aloglia 专家

这个问题将通过向您的模型添加 Laravel casts 变量来解决,很简单。

protected $casts = [
    'user_id' => 'integer',
    'agent_id' => 'integer',
    'company_person_id' => 'integer',
];

干杯!