Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel 5.4-将数据从excel文件保存到数据库_Php_Excel_Laravel 5.4 - Fatal编程技术网

Php Laravel 5.4-将数据从excel文件保存到数据库

Php Laravel 5.4-将数据从excel文件保存到数据库,php,excel,laravel-5.4,Php,Excel,Laravel 5.4,在这个帮助下,我正在阅读一个excel文件。这是我读取文件的函数: $path = base_path('public/uploads/' .$file->getClientOriginalName()); $rows = Excel::load($path, function($reader) { })->get()->toArray(); foreach($rows as $row) { dd($row); } 但是,由于excel表格没有列标题,我无法按列对数据进

在这个帮助下,我正在阅读一个excel文件。这是我读取文件的函数:

$path = base_path('public/uploads/' .$file->getClientOriginalName());
$rows = Excel::load($path, function($reader) { })->get()->toArray();

foreach($rows as $row) {
  dd($row);
}
但是,由于excel表格没有列标题,我无法按列对数据进行排序,这是将数据保存到DB所需的。 这是foreach循环中一行的外观:

array:7 [▼
  "amanda_storsenter" => "Amanda Storsenter"
  "apotek_1" => "Ark Bokhandel"
  10 => 10.0
  2547000 => 2547000.0
  18 => 27.0
  16 => 16.0
  20000 => 20000.0
]
我需要通过值的位置而不是键来访问这些值,因为我不知道所有行的键是什么样子。我不确定如何正确地执行此操作,因此我可以执行以下操作:

    $store = Store::create([
      'title' => $row[1],
      'visitors' => $row[6]
    ]);

你能不能试着把->get()的结果用var_转储一下,但是你没有用它,但是通过阅读文档,这里有一个注释“注意:默认情况下,这些属性将转换为slug。您可以在配置excel::import.heading中更改默认值。可用选项有:true | false |段塞| ascii |数值|哈希| trans |原始true和段塞将在excel::import.to | ascii设置为true时转换为ascii。您也可以在配置中更改默认分隔符。“从doc看,您必须在配置中设置
numerice
选项,以便获得数值索引而不是slug。是的,就是这样,非常感谢您的帮助@murtazabhurgriglay它起作用了:)