Laravel Excel 入力 API に問題があります。Excel のデータをデータベースに保存したいのですが、コード、Excel、およびエラーは次のとおりです。
Excel::selectSheets('CHS1')->load($uer->file, function($reader){
$x = 1;
$reader->limit(22);
$cell = $reader->get();
$data = [];
$data['nama'] = $cell[3 - $x][5 - $x];
$data['nim'] = $cell[4 - $x][5 - $x];
$data['jk'] = $cell[5 - $x][5 - $x];
$data['ttl'] = $cell[6 - $x][5 - $x];
$data['program'] = $cell[3 - $x][8 - $x];
$data['prodi'] = $cell[4 - $x][8 - $x];
$data['gelar'] = $cell[5 - $x][8 - $x];
$data['t_masuk'] = $cell[6 - $x][8 - $x];
$data['t_keluar'] = $cell[7 - $x][8 - $x];
foreach ($data as $key => $value) {
$data[$key] = preg_replace('/^(\'?: ?)/', '', $value);
}
// Jenis kelamin
$jk = [
'Laki-laki' => 'l',
'Perempuan' => 'p'
];
$indexJk = preg_replace('/\s/', '', $data['jk']);
$data['jk'] = $jk[$indexJk];
// Bulan setting
$month = [
'Januari' => '01',
'Febuari' => '02',
'Maret' => '03',
'April' => '04',
'Mei' => '05',
'Juni' => '06',
'Juli' => '07',
'Agustus' => '08',
'September' => '09',
'Oktober' => '10',
'November' => '11',
'Desember' => '12',
];
$ttl = explode(',', $data['ttl']);
$data['tempat'] = $ttl[0];
$tanggal = preg_replace('/^ ?/', '', $ttl[1]);
$tanggal = explode(' ', $tanggal);
$tgl = $tanggal[0];
$bln = $month[$tanggal[1]];
$thn = $tanggal[2];
$tanggal = $thn . '/' . $bln . '/' . $tgl;
$data['tgl'] = Carbon::parse($tanggal)->format('Y:m:d');
// Nilai
$nilai = [];
for($i = 9; $i < count($cell) - 2; $i++){
$nilai['matkul'][$i] = $cell[$i][5 - $x];
}
for($i = 9; $i < count($cell) - 2; $i++){
$nilai['smt'][$i] = $cell[$i][2 - $x];
}
for($i = 9; $i < count($cell) - 2; $i++){
$kode = [
'char' => $cell[$i][3 - $x],
'num' => $cell[$i][4 - $x]
];
$nilai['kode'][$i] = json_encode($kode);
}
for($i = 9; $i < count($cell) - 2; $i++){
$nilai['nilai'][$i] = $cell[$i][6 - $x];
}
for($i = 9; $i < count($cell) - 2; $i++){
$nilai['nilai_sk'][$i] = $cell[$i][7 - $x];
}
for($i = 9; $i < count($cell) - 2; $i++){
$nilai['krd'][$i] = $cell[$i][8 - $x];
}
for($i = 9; $i < count($cell) - 2; $i++){
$nilai['krp'][$i] = $cell[$i][9 - $x];
}
for($i = 9; $i < count($cell) - 2; $i++){
$nilai['akw'][$i] = $cell[$i][10 - $x];
}
$newNilai = [];
for($i = 9; $i < count($nilai['smt']) + 9; $i++){
foreach ($nilai as $key => $value) {
$newNilai[$i][$key] = $nilai[$key][$i];
}
}
$mahasiswa = Nil_mahasiswas::where('nim', $data['nim'])->get()->first();
$tbnilai;
if($mahasiswa){
$mahasiswa->nama = $data['nama'];
$mahasiswa->nim = $data['nim'];
$mahasiswa->jk = $data['jk'];
$mahasiswa->tempat = $data['tempat'];
$mahasiswa->tgl = $data['tgl'];
$mahasiswa->program = $data['program'];
$mahasiswa->prodi = $data['prodi'];
$mahasiswa->gelar = $data['gelar'];
$mahasiswa->t_masuk = $data['t_masuk'];
$mahasiswa->t_keluar= $data['t_keluar'];
$mahasiswa->save();
$id_mahasiswa = $mahasiswa->id;
$tbnilai = Nilais::where('id_mahasiswa', $id_mahasiswa)->get();
for($i = 0; $i < 9; $i++){
$nilai = $newNilai[$i+9];
$tbnilai = Nilais::where('id_mahasiswa', $id_mahasiswa)->get()[$i];
$tbnilai->delete();
CommonController::createNilai($tbnilai, $nilai, $id_mahasiswa);
}
}else{
Nil_mahasiswas::create([
'nama' => $data['nama'],
'nim' => $data['nim'],
'jk' => $data['jk'],
'tempat'=> $data['tempat'],
'tgl' => $data['tgl'],
'program'=> $data['program'],
'prodi' => $data['prodi'],
'gelar' => $data['gelar'],
't_masuk'=> $data['t_masuk'],
't_keluar'=> $data['t_keluar']
]);
$mahasiswa = Nil_mahasiswas::where('nim', $data['nim'])->get()->first();
$id_mahasiswa = $mahasiswa->id;
for($i = 0; $i < 9; $i++){
$nilai = $newNilai[$i+9];
CommonController::createNilai(new Nilais, $nilai, $id_mahasiswa);
}
}
});
そして、これは私のExcelがどのように見えるかです: