Files
nuhodds_fi4/app/Filament/Imports/Helper/ImportFixtures.php
T
2026-05-25 14:20:35 +02:00

47 lines
1.4 KiB
PHP

<?php
namespace App\Filament\Imports\Helper;
use App\Models\StatisticFixtures;
use Illuminate\Support\Carbon;
use Illuminate\Support\LazyCollection;
use Spatie\SimpleExcel\SimpleExcelReader;
class ImportFixtures
{
public static function run(string $filePath): void
{
SimpleExcelReader::create(storage_path('app/public/'.$filePath))
->getRows()
->chunk(200)
->each(function (LazyCollection $chunk) {
foreach ($chunk as $row) {
$row = array_values($row);
/*
0 => 1
1 => 87
2 => 3614
3 => 1491
4 => DateTimeImmutable @1777334400 {#2722 ▶}
5 => 0.90433699503783
6 => 1.035168989838
*/
StatisticFixtures::updateOrCreate(
[
'sport_id' => (int) $row[0],
'league_id' => (int) $row[1],
'home_id' => (int) $row[2],
'away_id' => (int) $row[3],
'starttime' => Carbon::parse($row[4])->toDateTimeString(),
],
['exp_home' => (float) $row[5], 'exp_away' => (float) $row[6]]
);
}
});
}
}