我的数据库中有两个表,一个practitioner和第二个practitioner_specialty,它们都有字段effective_date和expiry_date. 当我使用表单更新这两个表时,如果这些表是最后一个effective_date并且expiry_date被保存到两个表而不是两个单独的表。有没有办法阻止一个表更新,所以我只能更新第二个,或者有没有办法使用不同的 id/name 保存它,这样它们对于practitionerand 来说都是唯一的practitioner_specialty?
这是我用于更新表格的表单和控制器。
控制器:
public function updatePractitioner(Request $request, $id)
{
$this->validate($request, [
'effective_date' => 'required',
]
);
$fields = $request->all();
$primary_key = $this->PractitionerRepository->getIdName();
$primary_key_specialty = $this->PractitionerSpecialtyRepository->getIdName();
$practitioner_specialty_id = PractitionerSpecialty::where('practitioner_id', $id)->value('practitioner_specialty_id');
$fields[$primary_key] = $id;
$this->PractitionerRepository->update($fields);
$fields[$primary_key_specialty] = $practitioner_specialty_id;
$this->PractitionerSpecialtyRepository->update($fields);
return back()->with('successUpdate', 'Practitioner has been updated!');
}
慕婉清6462132