Files
Kent-logistics-Laravel/app/Imports/OrderItemsPreviewImport.php

27 lines
649 B
PHP
Raw Normal View History

2025-12-23 12:22:35 +05:30
<?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;
}
}
}
}