getRows() ->chunk(500) ->each(function (LazyCollection $chunk) use ($fieldnames) { foreach ($chunk as $row) { $row = array_values($row); $match_id = 0; $ss_player_id = 0; $update_array = []; foreach ($fieldnames as $key => $name) { if ($key == 1) { $match_id = (int) $row[$key]; // if (! $match_id) { // return false; // } } elseif ($key == 2) { $ss_player_id = (int) $row[$key]; } elseif ($key == 3) { $update_array['starttime'] = Carbon::parse($row[$key], config('app.timezone'))->setTimezone('UTC'); } else { $update_array[$name] = $row[$key]; } } StatistikoPlayer::updateOrCreate( [ 'match_id' => $match_id, 'ss_player_id' => $ss_player_id, ], $update_array ); } }); } }