我是Laravel的新手。我只是试图更新mysql表的一整行数据,数据来自表单。我只能更新2个记录,其余的变成了NULL。我确定Controller中的字段名与表单中的输入字段名以及mysql表中的字段名匹配。同时我也确保模型中 "fillable" 方法中列出的字段都被填充。
在Controller尝试过以下方法:
public function approve($id, Request $request)
{
$name = $request->input('name');
$mark = $request->input('mark');
$email = $request->input('email');
$dob = date('Y-m-d H:i:s', strtotime($request->input('dob')));
$country = $request->input('country');
Certificate::where('id', '=', $id)
->update([
'mark' => $mark,
'name' => $name,
'dob' => $dob,
'country' => $country
]);
}
我也尝试过
$query = DB::update("UPDATE certificates SET name='$name', mark='$mark', dob='$dob', country='$country' WHERE id='$id'");
请告诉我可能做错了什么,谢谢。