php - laravel 7.15 Undefined offset: 38 Maatwebsite Excel 导入导出
问题描述
我正在使用 Maatwebsite excel 导入和导出 xlsx 文件。我以前在其他应用程序中使用过它并且它正在工作。在我的第二个应用程序中,我遇到了一个错误。
未定义的偏移量:3
我不明白,我做错了什么。一切都和我的其他应用程序一样。
这是我的控制器:
$products = Excel::toArray(new ProductsImport(), $request->file('file'));
// dd($products);
foreach($products[0] as $row) {
$arr[] = [
'coil_id' => $row[1],
'category' => $row[2],
'product_family' => $row[3],
];
}
if(!empty($arr)){
DB::table('products')->insert($arr);
}
return back()->with('toast_success', 'Excel file uploaded to database successfully');
即使出口也不起作用。它只是将我带到一个空白页面 localhost/products/export
解决方案
推荐阅读
- javascript - 为什么要加上 270 度来校正旋转?
- python - 如何组合元组列表中的值?
- javascript - 调用 db.collection(collection).insertOne() 的 Node.js MongoDB 性能影响
- python - 从 2 个 1 维列表在 python 中创建 2 维列表
- kotlin - 有没有办法减少 Kotlin 编译器所需的内存?
- r - 如何识别R中行的镜像重复
- ruby-on-rails - 堆栈级别太深设置 Rails
- assembly - 如何在 MIPS 的 Integer 和 Float 数组中找到 Max 和 Min 值?
- json - 如何为其中的文本编写 XPath 查询