coolify/app/Events/ServiceStatusChanged.php

39 lines
899 B
PHP
Raw Normal View History

<?php
namespace App\Events;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class ServiceStatusChanged implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
2024-06-10 22:43:34 +02:00
2024-07-02 16:12:04 +02:00
public ?string $userId = null;
2024-06-10 22:43:34 +02:00
public function __construct($userId = null)
{
2023-12-08 13:07:42 +01:00
if (is_null($userId)) {
$userId = auth()->user()->id ?? null;
}
if (is_null($userId)) {
2024-07-02 16:12:04 +02:00
return false;
2023-12-08 13:07:42 +01:00
}
$this->userId = $userId;
}
2024-07-02 16:12:04 +02:00
public function broadcastOn(): ?array
{
2024-07-12 11:27:08 +02:00
if (! is_null($this->userId)) {
2024-07-02 16:12:04 +02:00
return [
new PrivateChannel("user.{$this->userId}"),
];
}
return null;
}
}