'domain', 3 => 'server_ip', 4 => 'api_url', 5 => 'webmaster_domain', 6 => 'report_day' ]; public function collection(Collection $collections) { // $allSites = Site::query()->get(); // $serverMap = Server::all()->pluck('server_id', 'server_ip')->toArray(); $all = collect([]); foreach ($collections as $key => $collection) { if ($key < 1 || empty($collection[0]) || empty($collection[2])) { continue; } $temp = $this->fieldMap($collection); $all->push($temp); } $items = $all->toArray(); $siteSync = new SiteSyncLogic(); foreach ($items as $key => $item) { $temp = $allSites->where('domain', $item['domain'])->first(); if ($temp) { $updated = [ 'server_id' => $serverMap[$item['server_ip']] ?? 0, 'api_url' => $item['api_url'], 'webmaster_domain' => $item['webmaster_domain'], 'report_day' => $item['report_day'] ]; $temp->update($updated); $syncUpdate = $temp->toArray() + ['server_ip' => $item['server_ip']]; $siteSync->update($temp->old_id, $siteSync->fieldMap($syncUpdate)); } else { echo $item['domain'] . '
'; } } dump('success'); } public function fieldMap($collect): array { $result = []; foreach ($collect as $inx => $val) { if (empty(self::FIELD_MAP[$inx])) continue; if (self::FIELD_MAP[$inx] == 'report_day') { $result[self::FIELD_MAP[$inx]] = intval($val); } else { $result[self::FIELD_MAP[$inx]] = $val; } } return $result; } }