fetchAll("SELECT `location_id`, MAX(`dts_last_rejected`) AS `dts_last_rejected` FROM `user_location_reject` GROUP BY `location_id`"); foreach($rejects as $reject) { $location_id = $reject["location_id"]; $dts_rejected = $reject["dts_last_rejected"]; $dts_threshold = (string) CarbonImmutable::parse($dts_rejected, "UTC")->subDays(30); $tests = $this->fetchAll("SELECT `id` FROM `test` WHERE `location_id`='$location_id' AND `status`='1' AND `dts_created` > '$dts_threshold'"); foreach($tests as $test) { $test_id = $test["id"]; $this->execute("UPDATE `test` SET `dts_rejected`='$dts_rejected' WHERE `id`='$test_id'"); } } } public function down() { $this->execute("UPDATE `test` SET `dts_rejected`=NULL WHERE 1"); } }