【发布时间】:2019-11-20 21:40:46
【问题描述】:
如果 user_id 已经存在,我正在尝试更新记录,如果在 laravel 中的 user_id 不存在,则插入新记录:
但我的用户 ID 在 $doctorProfile['user_id'] 数据正在插入,但用户 id 插入为 NULL:
我的控制器代码:
if($request->has('doctor_profile'))
{
$doctorProfile = $body['doctor_profile'];
$data_array = [
'user_id' => $doctorProfile['user_id'],
'medical_credentials' =>
$doctorProfile['medical_credentials'],
'registration_number' =>
$doctorProfile['registration_number'],
'registration_expiration_date' =>
$doctorProfile['registration_expiration_date'],
'dea_number' => $doctorProfile['dea_number'],
'dea_expiration_date' =>
$doctorProfile['dea_expiration_date'],
'dea_issue_date' => $doctorProfile['dea_issue_date'],
'npi_number' => $doctorProfile['npi_number'],
'billing_title' => $doctorProfile['billing_title'],
'billing_employment_type' =>
$doctorProfile['billing_employment_type'],
'other_employment_type' => $doctorProfile['other_employment_type'],
'nadean_number' => $doctorProfile['nadean_number'],
'upin' => $doctorProfile['upin'],
'wcb_authorization' => $doctorProfile['wcb_authorization'],
'wcb_rating_code' => $doctorProfile['wcb_rating_code'],
'wcb_date_of_issue' => $doctorProfile['wcb_date_of_issue'],
'hospital_privileges' => $doctorProfile['hospital_privileges'],
];
$medId = MedicalIdentifiers::firstOrCreate(['user_id' => $doctorProfile['user_id']], $data_array);
$medId->save();
}
【问题讨论】:
-
如果在调用 firstOrCreate 之前转储 $data_array,会得到什么?像 dd($data_array);?你能给我们看看数据吗
-
你在哪里声明
$body变量?您能告诉我们请求的结构吗?
标签: php laravel authentication