update(['last_import' => 'no']); SimpleExcelReader::create(storage_path('app/public/'.$filePath)) ->getRows() ->chunk(1000) ->each(function (LazyCollection $chunk) { $collection = []; foreach ($chunk as $row) { if ($row['player_name'] != '') { $row['is_active'] = 1; $row['last_import'] = 'yes'; $row['birthdate'] = isset($row['birthday']) ? Carbon::parse($row['birthday'])->format('Y-m-d') : ''; unset($row['birthday']); $row['last_update'] = Carbon::parse($row['last_update'])->format('Y-m-d H:i:s'); $collection[] = $row; } } StatistikoDetail::upsert( $collection, uniqueBy: [ 'ss_player_id', ], update: [ 'ss_team_id', 'player_name', 'ss_national_team_id', 'birthdate', 'height', 'nationality', 'position', 'preferred_foot', 'last_update', 'is_active', 'last_import', ]); }); StatistikoDetail::where('last_import', 'no')->update(['is_active' => 0, 'ss_team_id' => 0]); } }