27 lines
649 B
PHP
27 lines
649 B
PHP
|
|
<?php
|
||
|
|
namespace App\Imports;
|
||
|
|
|
||
|
|
use Maatwebsite\Excel\Concerns\ToCollection;
|
||
|
|
use Illuminate\Support\Collection;
|
||
|
|
|
||
|
|
class OrderItemsPreviewImport implements ToCollection
|
||
|
|
{
|
||
|
|
public array $rows = [];
|
||
|
|
|
||
|
|
public function collection(Collection $collection)
|
||
|
|
{
|
||
|
|
$header = $collection->first()->map(fn ($h) => strtolower(trim($h)))->toArray();
|
||
|
|
|
||
|
|
foreach ($collection->skip(1) as $row) {
|
||
|
|
$item = [];
|
||
|
|
foreach ($header as $i => $key) {
|
||
|
|
$item[$key] = $row[$i] ?? null;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!empty($item['description'])) {
|
||
|
|
$this->rows[] = $item;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|