删除 Sheet 父数组导入到 Laravel Excel 包上的集合或数组

Remove Sheet Parent Array Import to Collection or Array on Laravel Excel Package

我想导入 Excel 但只在 sheet 索引 [0] 上,但是当我使用 toCollection 或 toArray 方法时,行包装在 sheet 索引数组上:

我想删除包裹的父数组,怎么办?

这是我的代码:

Import.php

<?php

namespace App\Imports;

use Maatwebsite\Excel\Concerns\Importable;
use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
use Maatwebsite\Excel\Concerns\WithCalculatedFormulas;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;

class Import implements SkipsEmptyRows,
                        WithCalculatedFormulas,
                        WithMultipleSheets
{
    use Importable;

    /**
     * Select sheet by index and how they are
     * mapped to specific import object.
     *
     * @return array
     */
    public function sheets(): array
    {
        return [
            0 => new static(),
        ];
    }
}

控制器:

$filePath = 'import-excel.xlsx';
$import = new Import();
$rows = $import->toCollection($filePath);

dd($rows->toArray());

预期结果:

[0] => Array(
    [0] => *Contact Name
    [1] => *Contact Email
    [2] => *Contact Address
)

[1] => Array (
    [0] => Talia Oktaviani S.Psi
    [1] => nova03@yahoo.com
    [2] => Ds. Abdul No. 618 Tarakan 11408 KalU
)

实际结果:

Array(  <== ***I want remove this.***
    [0] => Array(  <== ***I want remove this.***
        [0] => Array(
            [0] => *Contact Name
            [1] => *Contact Email
            [2] => *Contact Address
        )

        [1] => Array (
            [0] => Talia Oktaviani S.Psi
            [1] => nova03@yahoo.com
            [2] => Ds. Abdul No. 618 Tarakan 11408 KalU
        )
    )  <== ***I want remove this.***
)  <== ***I want remove this.***

使用折叠功能可以删除

$filePath = 'import-excel.xlsx';
$import = new Import();
$rows = $import->toCollection($filePath)->collapse();

dd($rows->toArray());