Excel::import(new Import(), request()->file('filename'));
我想
$request->field1 , $request->fild2
从输入字段导入额外的字段。我正在使用 Maatwebsite\Excel
Excel::import(new Import(), request()->file('filename'));
我想
$request->field1 , $request->fild2
从输入字段导入额外的字段。我正在使用 Maatwebsite\Excel
您可以像这样简单地在导入中获取请求数据
<?php
namespace App\Imports;
use App\Model;
use Maatwebsite\Excel\Concerns\ToModel;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
class BulkImportLead implements ToModel,WithHeadingRow
{
public function model(array $row)
{
$request = request()->all();
$field1 = $request['field1'];
$field2 = $request['field2'];
//here your import code
}
}
只需使用这个:
namespace App\Imports;
use App\Models\Students;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Illuminate\Http\Request;
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']
]);
}
}