当我想运行我的导入脚本,我有这样的麻烦.我已经取代Excel加载()到Excel导入(),但这个soltion不工作.我应该怎么做来解决这个麻烦?当我想运行我的导入脚本,我有这样的麻烦.我已经取代Excel加载()到Excel导入(),但这个soltion不工作.我应该怎么做来解决这个麻烦?
public function postImport(Request $request)
{
// $this->validate($request, [
// 'file' => 'required|mimes:xls,xlsx'
// ]);
$path = $request->file('file')->getRealPath();
$data = Excel::load($path)->get();
// $data = Excel::toArray([],$path);
if($data->count() > 0)
{
foreach($data->toArray() as $key => $value)
{
foreach($value as $row)
{
$insert_data[] = array(
'nomorUrut' => $row[0],
'namaSupplier' => $row[1],
'singkatanSupplier' => $row[2],
'tipeSupplier' => $row[3],
'alamatSupplier' => $row[4],
'kodePosSupplier' => $row[5],
'noTelpSupplier' => $row[6],
'noFax' => $row[7],
'emailSupplier' => $row[8],
'contakSupplier' => $row[9],
'hp' => $row[10],
);
}
}
if(!empty($insert_data))
{
DB::table('uplSupplier')->insert($insert_data);
}
}
return back()->with('success', 'Excel Data Imported successfully.');
// }
2条答案
按热度按时间nr9pn0ug1#
我已经把接口供应商(作为UplSupplierImport)在app\Exports.我有其他的麻烦了,麻烦是“数组到字符串转换”.这是我的新接口供应商(作为UplSupplierImport),我已经把我的app/export.对于控制器的新代码与你之前的代码相同:
这是控制器代码:
}
vxf3dgd42#
Load方法从当前版本的Laravel Exel中删除。您可以考虑这样做:
创建导入类:
然后:
如果要使用import方法,请参考https://docs.laravel-excel.com/3.1/imports/batch-inserts.html