Files
nuhodds_fi4/app/Filament/Imports/Helper/ImportEvents.php
T
2026-07-15 10:30:09 +02:00

63 lines
2.4 KiB
PHP

<?php
namespace App\Filament\Imports\Helper;
use App\Models\StatistikoEvent;
use Illuminate\Support\Carbon;
use Illuminate\Support\LazyCollection;
use Spatie\SimpleExcel\SimpleExcelReader;
class ImportEvents
{
public static function run(string $filePath, string $importmode): void
{
$now = now()->format('Y-m-d H:i:s');
SimpleExcelReader::create(storage_path('app/public/' . $filePath))
->getRows()
->chunk(1000)
->each(function (LazyCollection $chunk) use ($now, $importmode) {
foreach ($chunk as $row) {
$row = array_values($row);
StatistikoEvent::updateOrCreate(
[
'match_id' => (int) $row[0],
],
[
'sport_id' => (int) $row[1],
'league_id' => (int) $row[2],
'home_id' => (int) $row[3],
'away_id' => (int) $row[4],
'starttime' => Carbon::parse($row[5])->toIso8601String(),
'season' => (string) $row[6],
'gls_h' => (int) $row[7],
'gls_a' => (int) $row[8],
'crn_h' => (int) $row[9],
'crn_a' => (int) $row[10],
'fls_h' => (int) $row[11],
'fls_a' => (int) $row[12],
'ofs_h' => (int) $row[13],
'ofs_a' => (int) $row[14],
'snt_h' => (int) $row[15],
'snt_a' => (int) $row[16],
'tsh_h' => (int) $row[17],
'tsh_a' => (int) $row[18],
'crd_h' => (int) $row[19],
'crd_a' => (int) $row[20],
'exp_home' => (float) $row[21],
'exp_away' => (float) $row[22],
'exp_handicap' => (float) $row[23],
'exp_total' => (float) $row[24],
'result_code' => $row[25], // w, d, l
'created_at' => $now,
'updated_at' => $now,
]
);
}
});
}
}