Added sockets for notifications
This commit is contained in:
@@ -21,20 +21,17 @@ class UpdateDepartedFlights extends Command
|
||||
{
|
||||
$now = now()->utc();
|
||||
|
||||
$now = now()->utc();
|
||||
|
||||
$userFlights = UserFlight::where('departure_date', '<=', $now->toDateTimeString())
|
||||
->where('departure_date', '>', $now->copy()->subMinute()->toDateTimeString())
|
||||
->where(function ($query) {
|
||||
$query->whereNull('departure_processed_at')
|
||||
->orWhereColumn('departure_processed_at', '<', 'departure_date');
|
||||
})
|
||||
->get();
|
||||
|
||||
$this->info("Found {$userFlights->count()} flights.");
|
||||
|
||||
foreach ($userFlights as $flight) {
|
||||
$flight->touch();
|
||||
$flight->update(['departure_processed_at' => $now]);
|
||||
}
|
||||
|
||||
$this->info("Touching flight {$flight->id}");
|
||||
$result = $flight->touch();
|
||||
$this->info("Touch result: " . var_export($result, true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ namespace App\Events;
|
||||
use App\Models\Notification;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class NotificationCreated implements ShouldBroadcast
|
||||
|
||||
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class UserFlight extends Model
|
||||
@@ -30,12 +31,14 @@ class UserFlight extends Model
|
||||
'crew_type_id',
|
||||
'note',
|
||||
'auto_update',
|
||||
'departure_processed_at'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'departure_date' => 'immutable_datetime',
|
||||
'arrival_date' => 'immutable_datetime',
|
||||
'auto_update' => 'boolean',
|
||||
'departure_processed_at' => 'datetime',
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
@@ -50,9 +53,17 @@ class UserFlight extends Model
|
||||
'livery_url',
|
||||
'scope',
|
||||
'range',
|
||||
'region_range'
|
||||
'region_range',
|
||||
];
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (UserFlight $flight) {
|
||||
$flight->departure_processed_at = now();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public function calculateGreatCircleDistance(): float{
|
||||
$earthRadiusKm = 6371;
|
||||
[$depLat, $depLong] = [$this->departureAirport->latitude_deg, $this->departureAirport->longitude_deg];
|
||||
@@ -182,7 +193,8 @@ class UserFlight extends Model
|
||||
return !$this->isDomestic();
|
||||
}
|
||||
|
||||
public function otherUsersOnFlight(){
|
||||
public function otherUsersOnFlight(): Collection
|
||||
{
|
||||
return UserFlight::where('user_id', '!=', $this->user_id)
|
||||
->where('departure_airport_id', $this->departure_airport_id)
|
||||
->where('arrival_airport_id', $this->arrival_airport_id)
|
||||
|
||||
Reference in New Issue
Block a user