lasthourcloud/app/Events/DatabaseStatusChanged.php

39 lines
889 B
PHP
Raw Normal View History

2023-12-11 08:02:53 +00:00
<?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 DatabaseStatusChanged implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
2024-06-10 20:43:34 +00:00
2024-07-02 14:12:04 +00:00
public ?string $userId = null;
2024-06-10 20:43:34 +00:00
2023-12-11 08:02:53 +00:00
public function __construct($userId = null)
{
if (is_null($userId)) {
$userId = auth()->user()->id ?? null;
}
if (is_null($userId)) {
2024-07-02 14:12:04 +00:00
return false;
2023-12-11 08:02:53 +00:00
}
$this->userId = $userId;
}
2024-07-02 14:12:04 +00:00
public function broadcastOn(): ?array
2023-12-11 08:02:53 +00:00
{
2024-07-02 14:12:04 +00:00
if ($this->userId) {
return [
new PrivateChannel("user.{$this->userId}"),
];
}
return null;
2023-12-11 08:02:53 +00:00
}
}