handleOnDb(); } else { //multiDB environment, need to foreach (MultiDB::$dbs as $db) { MultiDB::setDB($db); $this->handleOnDb(); } MultiDB::setDB($current_db); } } private function handleOnDb() { set_time_limit(0); Backup::whereRaw('html_backup IS NOT NULL')->chunk(5000, function ($backups) { foreach ($backups as $backup) { if(strlen($backup->html_backup) > 1 && $backup->activity->client()->exists()){ $client = $backup->activity->client; $backup->storeRemotely($backup->html_backup, $client); } } }); } }