Files
FlightsAPI/app/Console/Commands/UpdateDepartedFlights.php
2026-07-02 23:11:46 +10:00

35 lines
1.0 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Enums\FlightNotificationType;
use App\Models\UserFlight;
use App\Services\FollowerNotificationService;
use Illuminate\Console\Attributes\Description;
use Illuminate\Console\Attributes\Signature;
use Illuminate\Console\Command;
#[Signature('app:update-departed-flights')]
#[Description('Command description')]
class UpdateDepartedFlights extends Command
{
public function handle(): void
{
$now = now()->utc();
$userFlights = UserFlight::where('departure_date', '<=', $now->toDateTimeString())
->where(function ($query) {
$query->whereNull('departure_processed_at')
->orWhereColumn('departure_processed_at', '<', 'departure_date');
})
->get();
foreach ($userFlights as $flight) {
$flight->update(['departure_processed_at' => $now]);
new FollowerNotificationService()->notifyFlightEvent($flight, FlightNotificationType::Departed);
}
}
}