Laravel 5.7 导入 Excel 文件:未定义的偏移量

Laravel 5.7 Import Excel File: Undefined offset

我正在尝试导入 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],
    ]);

这是我的控制器代码:

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');

谁能帮我解决这个问题?我真的不知道如何处理这个错误。

错误表示行数组没有第 14 个位置。数组从 0 开始,因此在模型上访问 0 到 13 而不是 1 到 14。

将@放在行变量之前。 @$row[14]。如果行变量未定义,它将忽略。