Laravel 5 要查看的Laravel 5 Excel导入

Laravel 5 要查看的Laravel 5 Excel导入,laravel-5,laravel-excel,maatwebsite-excel,Laravel 5,Laravel Excel,Maatwebsite Excel,我正在使用maatwebsite Laravel Excel,我正在尝试导入csv,然后在视图中显示结果 导入CSV,然后像这样转储结果,我没有问题: object(Maatwebsite\Excel\Collections\RowCollection)#464 (2) { ["title":protected]=> string(9) "Worksheet" ["items":protected]=> array(3) { [0]=> obje

我正在使用maatwebsite Laravel Excel,我正在尝试导入csv,然后在视图中显示结果

导入CSV,然后像这样转储结果,我没有问题:

object(Maatwebsite\Excel\Collections\RowCollection)#464 (2) {
  ["title":protected]=>
  string(9) "Worksheet"
  ["items":protected]=>
  array(3) {
    [0]=>
    object(Maatwebsite\Excel\Collections\CellCollection)#472 (2) {
      ["title":protected]=>
      NULL
      ["items":protected]=>
      array(2) {
        ["name"]=>
        string(11) "Owen Kelley"
        ["age"]=>
        float(29)
      }
    }
    [1]=>
    object(Maatwebsite\Excel\Collections\CellCollection)#473 (2) {
      ["title":protected]=>
      NULL
      ["items":protected]=>
      array(2) {
        ["name"]=>
        string(9) "Jim Jones"
        ["age"]=>
        float(50)
      }
    }
    [2]=>
    object(Maatwebsite\Excel\Collections\CellCollection)#474 (2) {
      ["title":protected]=>
      NULL
      ["items":protected]=>
      array(2) {
        ["name"]=>
        string(10) "Sally Anne"
        ["age"]=>
        float(35)
      }
    }
  }
}
以下是我的控制器中的代码:

public function show()
{
    $results = Excel::load('public\uploads\file.csv', function($reader) {

        $reader->select(array('name', 'age'))->get();


    });

    return view('excel.show', compact('results'));

}
正如我前面提到的,如果我更改:
returnview('excel.show',compact('results')

然后我可以看到表中的所有数据,但我不知道如何将这些数据传递给视图

有人能帮我吗

我知道如果我想完成这项任务,我就应该知道这一点,但我对编码还是很陌生,而且时间紧迫

谢谢。

如果
$results->dump()
有效,将其传递给视图也很可能有效

我猜Laravel在您的视图中找不到excel.show。您能否向我们显示excel.show文件,并验证权限是否正确?

请尝试以下代码:

   $file= "test.xls";
    $data = Excel::load($file, function($reader) {

        foreach($reader->toArray()[0] as $row){             

        }
    })->get()->toArray()[0];

    return view('upload_load',compact('data'));

你愿意分享你的视图文件吗?返回视图时的输出是什么?请检查答案的代码。看起来这是一个悬而未决的注释宏结尾。
   $file= "test.xls";
    $data = Excel::load($file, function($reader) {

        foreach($reader->toArray()[0] as $row){             

        }
    })->get()->toArray()[0];

    return view('upload_load',compact('data'));