我正在尝试导入一个 excel 文件并将其保存到数据库中,但我得到了错误,我不知道这意味着什么,虽然我是 Laravel 的新手。
ErrorException (E_NOTICE) Undefined offset: 14
这是我的模型代码:
public function model(array $row)
{
return new Resident([
'resident_fname' => $row[1],
'resident_lname' => $row[2],
'resident_mi' => $row[3],
'resident_dob' => $row[4],
'role' => $row[5],
'resident_age' => $row[6],
'resident_address' => $row[7],
'resident_contact' => $row[8],
'resident_email' => $row[9],
'resident_purok' => $row[10],
'resident_status' => $row[11],
'resident_gender' => $row[12],
'resident_religion' => $row[13],
'ResidentVoter_status' => $row[14],
]);
这是我的 Controller 代码:
public function import(Request $request)
{
$import = Excel::import(new ResidentImport, request()->file('import_file'));
dd($import);
return view('pages.residents')->with('success', 'Imported Successfully');
}
这是我的文件按钮的代码:
<form action="{{ url('/import') }}" method="POST" enctype="multipart/form-data"></a>
{{ csrf_field() }}
<input type="file" name="import_file" style="direction: rtl;"></input>
<button type="submit" name="upload" class="btn btn-success">Submit</button></form>
这是我的路线:
Route::post('/import', 'ImportController@import');
谁能帮我这个?我真的不知道如何处理这个错误。
最佳答案
将 @ 放在行变量之前。 @$row[14]
.如果行变量未定义,它将忽略。
关于excel - Laravel 5.7 导入 Excel 文件 : Undefined offset,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55259627/