【发布时间】:2019-10-15 20:08:09
【问题描述】:
有一个字段位于数组中,我正在尝试更新我的值:
我的控制器代码:
<?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]
有人可以帮我修改这段代码吗? 提前谢谢你
【问题讨论】:
-
我认为问题出在
->value('id')->update- 为什么->value('id')是为了? -
根据“id”更新记录,这个id是主键
-
但这就是
where('user_id', $userProfile['id'])的作用 -
如果我删除 ->value('id) 然后它说 Call to a member function fill() on null
-
@syed1234 可能是 $userProfile['id'] 在表中不存在或为空,