2023-12-08 11:12:44 +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 ServiceStatusChanged implements ShouldBroadcast
|
|
|
|
{
|
|
|
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-12-08 11:12:44 +00:00
|
|
|
public $userId;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-12-08 11:12:44 +00:00
|
|
|
public function __construct($userId = null)
|
|
|
|
{
|
2023-12-08 12:07:42 +00:00
|
|
|
if (is_null($userId)) {
|
|
|
|
$userId = auth()->user()->id ?? null;
|
|
|
|
}
|
|
|
|
if (is_null($userId)) {
|
2024-06-10 20:43:34 +00:00
|
|
|
throw new \Exception('User id is null');
|
2023-12-08 12:07:42 +00:00
|
|
|
}
|
2023-12-08 11:12:44 +00:00
|
|
|
$this->userId = $userId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function broadcastOn(): array
|
|
|
|
{
|
|
|
|
return [
|
2023-12-11 09:23:10 +00:00
|
|
|
new PrivateChannel("user.{$this->userId}"),
|
2023-12-08 11:12:44 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|