getRows() ->chunk(1000) ->each(function (LazyCollection $chunk) use ($fieldnames) { foreach ($chunk as $row) { $row = array_values($row); $update_array = []; foreach ($fieldnames as $key => $name) { $update_array[$name] = $row[$key]; } $sport_id = (int) $row['sport_id']; $match_id = (int) $row['match_id']; $ss_player_id = (int) $row['ss_player_id']; unset($row['sport_id']); unset($row['match_id']); unset($row['ss_player_id']); StatistikoPlayer::updateOrCreate( [ 'sport_id' => $sport_id, 'match_id' => $match_id, 'ss_player_id' => $ss_player_id, ], $update_array ); } }); } }