Пожалуйста, проверьте правильность обновления моей информации или нет.
error Integrity constraint violation: 1062 Duplicate entry '45' for key 'PRIMARY' (SQL: update `studentdetails` set `SID` = 45, `fname` = sds, `lname` = sad, `dob` = 2020-04-22, `gender` = male, `created_at` = 2020-04-29 11:55:43)"
Композитный ключ
Стол студенческий подробно
SID pk,
fname,
lname,
dob,
gender
Таблица студенческого адреса
SID pk,
zipcode pk,
street,
hname,
city,
state,
country
Таблица студенческого набора
SID pk,
grade pk,
edate
Контроллер:
public function update($SID,Request $request)
{
if(is_numeric($SID))
{
$SID = $request->get('SID');
$fname = $request->get('fname');
$lname = $request->get('lname');
$dob = $request->get('dob');
$gender = $request->get('gender');
$zipcode = $request->get('zipcode');
$city = $request->get('city');
$state = $request->get('state');
$country = $request->get('country');
$street = $request->get('street');
$hname = $request->get('hname');
$grade = $request->get('grade');
$edate = $request->get('edate');
if(is_numeric($SID) && !empty($fname) && !empty($lname) && !empty($dob) && !empty($gender)
&& is_numeric($zipcode) && !empty($city) && !empty($state) && !empty($street) && !empty($hname) && !empty($country)
&& !empty($grade) && !empty($edate))
{
DB::table('studentdetails')->update([
'SID' =>$SID,
'fname' =>$fname,
'lname' =>$lname,
'dob' =>$dob,
'gender' =>$gender,
'created_at' =>date('Y-m-d H:i:s'),
]);
DB::table('studentaddress')->update([
'SID' =>$SID,
'zipcode' =>$zipcode,
'city' =>$city,
'state' =>$state,
'country' =>$country,
'street' =>$street,
'hname' =>$hname,
'created_at' =>date('Y-m-d H:i:s'),
]);
DB::table('studentenrollment')->update([
'SID' =>$SID,
'grade' =>$grade,
'edate' =>$edate,
'created_at' =>date('Y-m-d H:i:s'),
]);
return MyResponse::success('ระบบได้บันทึกข้อมูลเรียบร้อยแล้ว','/student');
}else{
return MyResponse::error('กรุณาป้อนข้อมูลให้ครบ');
}
}