我已经使用barryvdh/laravel- dompdf Laravel 包来导入 Excel 文件,但在随附的屏幕截图中出现了上述错误。
if ($request->hasFile('upload_mcq_file') and in_array($request->upload_mcq_file->extension(), array('xlsx', 'xlt', 'xltx', 'xls', 'xls', 'csv'))) {
$image = $request->upload_mcq_file;
$fileName = time() . '.' . $image->getClientOriginalName();
$image->move('admin/mcqs/', $fileName);
$path = 'admin/mcqs/' . $fileName;
}
$data = Excel::import(new MCQPaperImport, $path);
MCQPaperImport类如下:
class MCQPaperImport implements ToModel
{
public function model(array $row)
{
return new MCQPaper([
'product_id' => request('product_id'),
'product_type' => request('product_type'),
'question' => $row[0],
'answer' => $row[1],
'option1' => $row[2],
'option2' => $row[3],
'option3' => $row[4],
'option4' => $row[5],
'mark' => $row[6],
'created_at' => Carbon::now('Asia/Kolkata'),
'updated_at' => Carbon::now('Asia/Kolkata'),
]);
}
}