where('source_system', 'wp') ->where('source_table', 'wp_posts') ->where('target_table', 'entries' ) ->get(['source_id', 'target_id']) ; $updated = 0; foreach ($rows as $row) { $downloadCount = DB::connection('old_wp') ->table('postmeta') ->where('post_id', $row->source_id) ->where('meta_key', 'download_counter' ) ->value('meta_value'); if( $downloadCount ) { DB::table('entries')->where('id', $row->target_id)->update(['old_download_count' => intval($downloadCount)]); $updated++; } } $this->info('All done (' . $updated . '/' . count($rows) .')'); } }