Как обновить данные в laravel - в данных есть значение массива - PullRequest
0 голосов
/ 30 мая 2019

Есть поле 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 Ответ

0 голосов
/ 30 мая 2019

UserBasicInfo::where('user_id', $userProfile['id']) является экземпляром Builder . Вы должны получить экземпляр Model , чтобы обновить его. Итак, попробуйте:

 UserBasicInfo::where('user_id', $userProfile['id'])->first()->update([...]);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...