SQLSTATE [01000]:警告:1265列“ id_paket”的数据被截断 第1行(SQL:插入
tbl_pesanan
(id_paket
,kode_bmn
,kode_unit
,jenis_barang
,kuantitas
,satuan_ukuran
,status_pesanan
)值(18,18,1010101002,1010101002,1001,1001, ASus,ASus,6,6,UNit,UNit,1))
发生了什么事,您能帮我吗?
public function store_pesanan(request $request,$id){
if(!Session::get('login')){
return redirect('/login')->with('alert','Kamu harus login dulu');
}
else{
DB::table('tbl_paket')
->where('id_paket',$id)
->update(['status_paket' => $request->status_paket]);
$data = new ModelPesanan();
$data->id_paket = implode(',', $request->input('id_paket'));
$data->kode_bmn = implode(',', $request->input('kode_bmn'));
$data->kode_unit = implode(',', $request->input('kode_unit'));
$data->jenis_barang = implode(',', $request->input('jenis_barang'));
$data->kuantitas = implode(',', $request->input('kuantitas'));
$data->satuan_ukuran = implode(',', $request->input('satuan_ukuran'));
$data->status_pesanan = $request->get('status_pesanan');
$data->save();
Alert::success('Sukses!', 'Berhasil Menambahkan Pesanan!');
return redirect ('/daftar_paket');
}
}
答案 0 :(得分:1)
问题似乎是您试图在字段id_paket
中插入太长的值。检查id_paket
的类型和大小,并与您的查询发送的内容进行比较:18,18
答案 1 :(得分:0)
除非将数组保留为json,否则请勿尝试将数组保存到单个字段中。
我认为您正在尝试创建两个ModelPesanan
?如果是这样,假设id_paket是外键,并且id_paket数组的键对于请求中的所有其他数组都相同,则可以尝试:
DB::table('tbl_paket')
->where('id_paket',$id)
->update(['status_paket' => $request->status_paket]);
foreach($request->input('id_paket') as $index => $idPaket){
$data = new ModelPesanan();
$data->id_paket = $request->input('id_paket')[$index];
$data->kode_bmn = $request->input('kode_bmn')[$index];
$data->kode_unit = $request->input('kode_unit')[$index];
$data->jenis_barang = $request->input('jenis_barang')[$index];
$data->kuantitas = $request->input('kuantitas')[$index];
$data->satuan_ukuran = $request->input('satuan_ukuran')[$index];
$data->status_pesanan = $request->get('status_pesanan');
$data->save();
}
Alert::success('Sukses!', 'Berhasil Menambahkan Pesanan!');
return redirect ('/daftar_paket');