簡體   English   中英

如何更新laravel中的數據 - 數據中有數組值

[英]How to update data in laravel - there is array value in data

有字段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]

有人可以幫我修改這個代碼我堅持這個你的幫助將非常感謝!
先感謝您

UserBasicInfo::where('user_id', $userProfile['id'])是一個Builder實例。 你應該讓Model實例更新它。 所以,試試:

 UserBasicInfo::where('user_id', $userProfile['id'])->first()->update([...]);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM