SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: '["2"]' for column `stagen`.`imunisasis`.`id_j_imun` at row 1

huangapple go评论76阅读模式
英文:

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

我在更新数据时遇到了问题。

Imunisasi 控制器

public function update(Request $request, $id)
{
    // 接收请求数据
    $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' => '数据更新成功']);
}

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');
    $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');
});
英文:
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']);
}

huangapple
  • 本文由 发表于 2023年8月9日 15:51:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76865659.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定