我面临一个未定义偏移的问题:第3行中的1。我无法理解它是什么类型的错误。任何人都可以告诉我为什么这样的错误发生在laravel
我的控制器:
public function store(Request $request)
{
$kode_tempat_ujian = $request-> input ('kode_tempat_ujian');
$kode_jenis_ujian = $request-> input ('kode_jenis_ujian');
$kode_jenis_d20an = $request-> input ('kode_jenis_d20an');
$hari = $request-> input ('hari');
$ruang = $request-> input ('ruang');
$kode_lokasi_ujian = $request-> input ('kode_lokasi_ujian');
$data = new AlokasiRuang;
$simpan = $data->IsiAlokasiRuang($kode_tempat_ujian, $kode_jenis_ujian, $kode_jenis_d20an, $hari, $ruang, $kode_lokasi_ujian);
if($simpan){
Session::flash('message', [ 'message' => 'Data Berhasil Ditambahkan',
'action'=>'success' ] );
return redirect('master/alokasiruang');
}else{
Session::flash('message', [ 'message' => 'Data Gagal Ditambakan Karena Primary Key Sudah Digunakan',
'action'=>'error' ] );
return redirect('master/alokasiruang');
}
}
public static function IsiAlokasiRuang ($kode_tempat_ujian, $kode_jenis_ujian, $kode_jenis_d20an, $hari, $ruang, $kode_lokasi_ujian)
{
try {
$isi = DB::insert( DB::raw("INSERT into t_alokasi_ruang_ujian (kode_tempat_ujian, kode_jenis_ujian, kode_jenis_d20an, hari, ruang, kode_lokasi_ujian)
values (:kode_tempat_ujian, :kode_jenis_ujian, :kode_jenis_d20an, :hari, :ruang, :kode_lokasi_ujian)"),
array( 'kode_tempat_ujian' => $kode_tempat_ujian, 'kode_jenis_ujian' => $kode_jenis_ujian, 'hari' => $hari, 'ruang' => $ruang, 'kode_lokasi_ujian' => $kode_lokasi_ujian
));
return $isi;
}catch (QueryException $e) {
$errorCode = $e->errorInfo[1]; //<== this is line 83
if($errorCode == 1062){
return false;
}
}
}
错误日志:
Whoops, looks like something went wrong.
1/1 ErrorException in AlokasiRuang.php line 83: Undefined offset: 1
in AlokasiRuang.php line 83
at HandleExceptions->handleError('8', 'Undefined offset: 1', 'D:\lokalapp\srs4g1\app\Models\Master\AlokasiRuang.php', '83', array('kode_tempat_ujian' => '101', 'kode_jenis_ujian' => '3', 'kode_jenis_d20an' => '4', 'hari' => '2', 'ruang' => '555', 'kode_lokasi_ujian' => '10B', 'e' => object(QueryException))) in AlokasiRuang.php line 83
at AlokasiRuang::IsiAlokasiRuang('101', '3', '4', '2', '555', '10B') in AlokasiRuangController.php line 110
at AlokasiRuangController->store(object(Request))
at call_user_func_array(array(object(AlokasiRuangController), 'store'), array(object(Request))) in Controller.php line 80
at Controller->callAction('store', array(object(Request))) in ControllerDispatcher.php line 146
at ControllerDispatcher->call(object(AlokasiRuangController), object(Route), 'store') in ControllerDispatcher.php line 94
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 96
at ControllerDispatcher->callWithinStack(object(AlokasiRuangController), object(Route), object(Request), 'store') in ControllerDispatcher.php line 54
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\Master\AlokasiRuangController', 'store') in Route.php line 174
at Route->runController(object(Request)) in Route.php line 140
at Route->run(object(Request)) in Router.php line 724
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 64
所以,谢谢你,我知道它的愚蠢,我刚开始使用laravel。提前致谢