alliance_id !== null) { $this->syncAllianceThresholds(); } } public function updated(Airline $airline): void { if ($airline->wasChanged('alliance_id')) { $this->syncAllianceThresholds(); } } public function deleted(Airline $airline): void { $this->syncAllianceThresholds(); } private function syncAllianceThresholds(): void { Alliance::withCount('airlines')->each(function (Alliance $alliance) { Achievement::where('internal_name', "airlines_alliances.all_{$alliance->internal_name}") ->update(['threshold' => $alliance->airlines_count]); }); } }