数组中有字段affiliated_facility,我正在尝试更新值:
我的控制器代码:
<?php
$affiliated_facility = implode(",", $userProfile['affiliated_facility']);
$userBasicInfoId = UserBasicInfo::where('user_id', $userProfile['id'])->value('id')->update([
'work_phone' => $userProfile['work_phone'],
'fax' => $userProfile['fax'],
'extension' => $userProfile['extension'],
'primary_facility' => $userProfile['primary_facility'],
'employed_by' => $userProfile['employed_by'],
'emergency_phone' => $userProfile['emergency_phone'],
'designation' => $userProfile['designation'],
'department' => $userProfile['department'],
'employment_type' => $userProfile['employment_type'],
'biography' => $userProfile['biography'],
'hiring_date' => $userProfile['hiring_date'],
'from' => $userProfile['from'],
'to' => $userProfile['to'],
'affiliated_facility' => $affiliated_facility]); // this is in array so I used implode in top of this code
if ($userBasicInfoId) {
$userBasicInfo = $this->userBasicInfo->find($userBasicInfoId);
$userBasicInfo->fill($userProfile)->save();
} else {
$userBasicInfo = $this->userBasicInfo->create($request->only($this->userBasicInfo->getModel()->fillable));
}
?>
但是当我点击我的请求时
对整数调用成员函数update()
我的代码中有一些错误。我想更新我的记录,但有一个数组中的字段:
"affiliated_facility": [1,2]
如何修改此代码?
1条答案
按热度按时间ccrfmcuu1#
UserBasicInfo::where('user_id', $userProfile['id'])
是一个Builder示例。您应该获取Model示例来更新它。因此,请尝试: