英文:
SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: '["2"]' for column `stagen`.`imunisasis`.`id_j_imun` at row 1
问题
update `imunisasis` set `id_j_imun` = "2", `tgl_imun` = '2023-08-09', `ket_imun` = 'asdasdsada', `imunisasis`.`updated_at` = '2023-08-09 07:29:27' where `id_imun` = 5
英文:
update `imunisasis` set `id_j_imun` = ["2"], `tgl_imun` = 2023-08-09, `ket_imun` = asdasdsada, `imunisasis`.`updated_at` = 2023-08-09 07:29:27 where `id_imun` = 5
I'm having trouble updating data.
**Imunisasi Controller **
public function update(Request $request, $id)
{
// menerima data request
$data = Imunisasi::where('id_imun', $id)->first();
$data->id_anak = $request->get('id_anak');
$data->id_j_imun = $request->get('id_j_imun');
$data->tgl_imun = $request->get('tgl_imun');
$data->booster = $request->get('booster');
$data->ket_imun = $request->get('ket_imun');
$data->save();
return redirect()->route('imunisasi')->with(['success' => 'Data Berhasil Di Update']);
}
Database Imunisasi
Schema::create('imunisasis', function (Blueprint $table) {
$table->increments('id_imun');
$table->unsignedInteger('id_anak');
$table->unsignedInteger('id_j_imun');
$table->date('tgl_imun');
$table->string('booster');`your text`
$table->string('ket_imun')->nullable();
$table->timestamps();
$table->foreign('id_anak')->references('id_anak')->on('anaks');
$table->foreign('id_j_imun')->references('id_j_imun')->on('jenis_imunisasis');
});
答案1
得分: 0
确保您为id_j_imun
列提供有效的整数值。
public function update(Request $request, $id)
{
// 接收请求数据
$data = Imunisasi::where('id_imun', $id)->first();
$data->id_anak = $request->get('id_anak');
// 确保值被转换为整数
$data->id_j_imun = (int)$request->get('id_j_imun');
$data->tgl_imun = $request->get('tgl_imun');
$data->booster = $request->get('booster');
$data->ket_imun = $request->get('ket_imun');
$data->save();
return redirect()->route('imunisasi')->with(['success' => '数据成功更新']);
}
英文:
Ensure you're providing a valid integer value for the id_j_imun
column.
public function update(Request $request, $id)
{
// menerima data request
$data = Imunisasi::where('id_imun', $id)->first();
$data->id_anak = $request->get('id_anak');
// Make sure the value is cast to an integer
$data->id_j_imun = (int)$request->get('id_j_imun');
$data->tgl_imun = $request->get('tgl_imun');
$data->booster = $request->get('booster');
$data->ket_imun = $request->get('ket_imun');
$data->save();
return redirect()->route('imunisasi')->with(['success' => 'Data Berhasil Di Update']);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论