46 lines
1.4 KiB
PHP
46 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, $sport_id): void
|
|
{
|
|
SimpleExcelReader::create(storage_path('app/public/'.$filePath))
|
|
->getRows()
|
|
->chunk(200)
|
|
->each(function (LazyCollection $chunk) use ($sport_id) {
|
|
|
|
foreach ($chunk as $row) {
|
|
|
|
$row = array_values($row);
|
|
|
|
/*
|
|
0 => 87
|
|
1 => 3614
|
|
2 => 1491
|
|
3 => DateTimeImmutable @1777334400 {#2722 ▶}
|
|
4 => 0.90433699503783
|
|
5 => 1.035168989838
|
|
*/
|
|
|
|
StatisticFixtures::updateOrCreate(
|
|
[
|
|
'sport_id' => (int) $sport_id,
|
|
'league_id' => (int) $row[0],
|
|
'home_id' => (int) $row[1],
|
|
'away_id' => (int) $row[2],
|
|
'starttime' => Carbon::parse($row[3])->toDateString(),
|
|
],
|
|
['exp_home' => (float) $row[4], 'exp_away' => (float) $row[5]]
|
|
);
|
|
}
|
|
});
|
|
}
|
|
}
|