Excel::import(new Import(), request()->file('filename'));
我想导入额外的字段$request->field1 , $request->fild2
来自输入字段。。我正在使用Maatewbsite\Excel
您可以简单地在导入中获得请求数据,如以下
<?php
namespace AppImports;
use AppModel;
use MaatwebsiteExcelConcernsToModel;
use IlluminateHttpRequest;
use MaatwebsiteExcelConcernsWithHeadingRow;
class BulkImportLead implements ToModel,WithHeadingRow
{
public function model(array $row)
{
$request = request()->all();
$field1 = $request['field1'];
$field2 = $request['field2'];
//here your import code
}
}
只需使用这个:
namespace AppImports;
use AppModelsStudents;
use MaatwebsiteExcelConcernsToModel;
use MaatwebsiteExcelConcernsWithHeadingRow;
use IlluminateHttpRequest;
class StudentsImport implements ToModel, WithHeadingRow
{
public function model(array $row)
{
$request = request()->all();
return new Students([
'matno'=> $row['matno'],
'name'=> $row['name'],
'dept'=> $row['dept'],
'level'=> $row['level'],
'deptid'=> $request['deptid']
]);
}
}