У меня есть файл Excel, и я хочу загрузить и сохранить данные в базу данных. если заголовок в первой строке, мой код ниже работает отлично,
но если заголовок, как на картинке ниже, мой код - ошибка, как прочитать заголовок, если у меня есть таблица, как показано ниже
if($request->hasFile('file')){
$extension = File::extension($request->file->getClientOriginalName());
if ($extension == "xlsx" || $extension == "xls" || $extension == "csv") {
$path = $request->file->getRealPath();
$data = Excel::load($path, function($reader) {
})->get();
if(!empty($data) && $data->count()){
foreach ($data as $value) {
$insert['data'] = [
'no' => $value->no,
'name' => $value->name,
'ic_no' => $value->ic_no,
'disburse_date' => $value->disburse_date,
'product_type_description' => $value->product_type_description,
'amount_release' => $value->amount_release,
'amount' => $value->amount,
'date_disburse' => $value->date_disburse,
'net_disbursement' => $value->net_disbursement,
];
Loandisburse::where('ic', $value['ic_no'])
->where('stage','W11')
->update(array('status_upload'=>'1',
'amount_release' => $value['amount_release'],
'amount' => $value['amount'],
'date_disburse' => $value['date_disburse'],
'net_disbursement' => $value['net_disbursement'],
'disburse_date' => $value['disburse_date'],
'product_type_description' => $value['product_type_description'],
'hash'=> $hash,
'month'=> $month,
'year'=>$nyear
));
}
}
return redirect('/upload/amount');
}
}