ここに私のExcelデータシートタイプがあります:
ここに私のテーブルスキーマがあります:
データをインポートする私の方法は次のとおりです。
public function saveActivationInfoExcel(Request $request)
{
if($request->hasFile('import_file')){
$path = $request->file('import_file')->getRealPath();
$data = Excel::load($path, function($reader) {})->get();
if(!empty($data) && $data->count()){
foreach ($data->toArray() as $key => $value) {
if(!empty($value)){
foreach ($value as $v) {
$insert[] = [
'mobile_no' =>$v['mobile_no'],
'model' => $v['model'],
'serial_1' => $v['serial_1'],
'serial_2' => $v['serial_2'],
'activation_date' => $v['activation_date'],
];
}
}
}
dd($insert);
if(!empty($insert)){
//ProductActivationInfo::insert($insert);
return back()->with('success','Insert Record successfully.');
}
}
}
return back()->with('error','Please Check your file, Something is wrong there.');
}
今私の問題は、データをインポートしようとすると、この dd($insert) エラーが発生することです
Illegal string offset 'mobile_no'
'serial_1' => '3.5194508009307E+14',
'serial_2' => '3.5194508009307E+14',
'activation_date' => object(Carbon), null)
実際のExcelの値ではなく、serial_1とserial_2の両方が異なる値を示しているのを見てください。また、activation_date の値が null です。
「maatwebsite/excel」laravel ライブラリを使用したデータの読み取りに関して、これを解決するための貴重な提案をいただければ幸いです。