我是Laravel的新手。我只是试图更新一整行的mysql表。正在从表单发送数据。我只更新了2条记录,其余的都变为NULL。我确定Controller的字段名称与mysql表中的表单中的输入字段名称匹配。我还确保该字段在模型的“可填充”方法中列出。
在控制器中尝试过:
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'");
请让我知道我可能做错了什么。谢谢
使用DB Facade,我遇到了与此类似的错误,所以这就是我所使用的
use Illuminate\Support\Facades\DB;
DB::table('certificates')
->where('id', $id)
->update([
'mark' => $request->mark,
'name' => $request->name,
'email' => $request->email,
'dob' => $request->dob,
'country' => $request->country
]);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句