65 lines
2.2 KiB
PHP
65 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Imports\Helper;
|
|
|
|
use App\Models\StatistikoDetail;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\LazyCollection;
|
|
use Spatie\SimpleExcel\SimpleExcelReader;
|
|
|
|
class ImportDetails
|
|
{
|
|
public static function run(string $filePath): 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) {
|
|
|
|
foreach ($chunk as $row) {
|
|
|
|
$row = array_values($row);
|
|
|
|
if ($row[1] != '') {
|
|
|
|
// 'ss_player_id',
|
|
// 'player_name',
|
|
// 'tx_team_id',
|
|
// 'ss_national_team_id',
|
|
// 'team_name',
|
|
// 'birthday',
|
|
// 'height',
|
|
// 'nationality',
|
|
// 'position',
|
|
// 'preferred_foot',
|
|
// 'last_update',
|
|
// 'created_at',
|
|
// 'updated_at',
|
|
|
|
StatistikoDetail::updateOrCreate(
|
|
[
|
|
'ss_player_id' => (int) $row[0],
|
|
],
|
|
[
|
|
'player_name' => $row[1],
|
|
'tx_team_id' => $row[2],
|
|
'ss_national_team_id' => $row[3],
|
|
'team_name' => $row[4],
|
|
'birthdate' => Carbon::parse($row[5])->toDateString(),
|
|
'height' => $row[6],
|
|
'nationality' => $row[7],
|
|
'position' => $row[8],
|
|
'preferred_foot' => $row[9],
|
|
'last_update' => Carbon::parse($row[10])->toDateString(),
|
|
'created_at' => $now,
|
|
'updated_at' => $now,
|
|
]
|
|
);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|