[英]How to update data in laravel - there is array value in data
There is field affiliated_facility which is in array and i am trying to update my values: 有字段affiliated_facility在阵列中,我正在尝试更新我的值:
My controller code: 我的控制器代码:
<?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));
}
?>
But when I hit my request it says 但当我按照我的要求说它
Call to a member function update() on integer 调用整数上的成员函数update()
There is some mistakes in my code i want to update my record and there is one field coming which is in array 我的代码中存在一些错误,我想更新我的记录,并且有一个字段在数组中
"affiliated_facility": [1,2]
can someone please help me to modify this code i am stuck on this your help will be highly appreciated! 有人可以帮我修改这个代码我坚持这个你的帮助将非常感谢!
Thankyou in advance 先感谢您
UserBasicInfo::where('user_id', $userProfile['id'])
is a Builder instance. UserBasicInfo::where('user_id', $userProfile['id'])
是一个Builder实例。 you should get Model instance to update it. 你应该让Model实例更新它。 So, try:
所以,试试:
UserBasicInfo::where('user_id', $userProfile['id'])->first()->update([...]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.