Added achievement data

This commit is contained in:
2026-04-26 20:00:11 +10:00
parent f6d5b97784
commit 14aed7bf6e
18 changed files with 950 additions and 6 deletions
+37
View File
@@ -0,0 +1,37 @@
<?php
namespace App\Observers;
use App\Models\Achievement;
use App\Models\Airline;
use App\Models\Alliance;
class AirlineObserver
{
public function created(Airline $airline): void
{
if ($airline->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]);
});
}
}