如何处理这种数据

我在这个项目中使用了laravel-5.4“maatwebsite / excel”

我打算为我的网站创build一个function,我可以上传一个excel文件,然后在我的视图中显示这个文件的数据

我用来上传和发送我的数据到后端的表单

public function bundleaddstudent(Request $request) { if($request->hasFile('excelstudent')){ $File = $request->file('excelstudent'); $path = $File->getRealPath(); $data = Excel::load($path, function($reader) { })->toObject(); return view('User.content.tobe_added_students') ->with('selection', $this->selection()) ->with('Students', $data); } else { return view('User.content.Add_student') ->with('selection', $this->selection()) ->with('Students', 'No Data') ->with('request', $request); } } 

现在已经上传的文件已经在我的控制器中被处理,它被转换为数据对象,并且也被传递给新的视图。

我现在需要在我看来处理传递的数据, 这是我做的

  @isset($Students) @foreach ($Students as $key => $value) <tr> <td> {{$value}}</td> </tr> @endforeach @endisset 

但不幸的是,这样的输出是这样的

在这里输入图像说明

如果我尝试{{ $value->dump() }}

方法转储不存在会发生错误

如果我尝试{{$ key}}

输出是一个从0 – 4开始输出的整数

 ---------------------------- | studentID | Firstname | ---------------------------- | 1 | | | 2 | | | 3 | | | 4 | | 

你得到的想法

我也尝试了{{ $value->studentId }}但它没有显示任何东西

在这里输入图像说明

基于@LrdArc的评论,我应该尝试

 @isset( $Students ) {{ dd( $Students ) }} @endisset 

OUTPUT:

 LaravelExcelReader {#353 ▼ +excel: PHPExcel {#361 ▶} +reader: PHPExcel_Reader_Excel2007 {#354 ▶} +file: "/tmp/phpu3zVBH" +columns: [] +title: "phpu3zVBH" +ext: "" +encoding: false +format: "Excel2007" +parsed: RowCollection {#430 ▼ #title: "Sheet1" #items: array:5 [▼ 0 => CellCollection {#495 ▼ #title: null #items: array:9 [▼ "studentid" => "15-2000332" "firstname" => "Dummy1" "lastname" => "Dummy1" "middlename" => "Dummy1" "course" => "Dummy1" "ay" => "Dummy1" "gender" => "Dummy1" "address" => "Dummy1" "contact" => "Dummy1" ] } 1 => CellCollection {#496 ▼ #title: null #items: array:9 [▼ "studentid" => "15-2000333" "firstname" => "Dummy2" "lastname" => "Dummy2" "middlename" => "Dummy2" "course" => "Dummy2" "ay" => "Dummy2" "gender" => "Dummy2" "address" => "Dummy2" "contact" => "Dummy2" ] } 2 => CellCollection {#515 ▶} 3 => CellCollection {#514 ▶} 4 => CellCollection {#513 ▶} ] } 

编辑:好的,我刚刚testing过。 在控制器中将toObject()更改为get()。

这是一个对象。 在你的观点中尝试这样的事情:

 @isset( $Students ) @foreach ( $Students as $student ) <tr> <td>{{ $student->studentID }}</td> <td>{{ $student->firstname }}</td> <td>{{ $student->lastname }}</td> <td>{{ $student->middlename }}</td> </tr> @endforeach @endisset