excel - Laravel 5.7 导入 Excel 文件 : Undefined offset

标签 excel database laravel import laravel-5.7

我正在尝试导入一个 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/

相关文章:

excel - 将细胞彼此连接起来;让单元格更新链接的单元格,反之亦然

php - 通过php将MySQL数字转换为货币?

mysql - 我可以在 laravel 数据库查询中使用 if 条件吗?

php - ERR_ICANN_NAME_COLLISION 在主机文件中使用 url 而不是 ip

JavaScript/React/Node : Writing values to an existing excel file with condition

excel - "Procedure too Large"错误

excel,正在查看哪个 "data connections have been disabled"

mysql - 如何在此 sql 查询中使用 0-20 之间的范围?

MySQL - 如何创建复合表?

laravel - 如何在 Laravel 中调用响应