44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Events;
|
|
|
|
use App\Models\ReportDuty;
|
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
|
use Illuminate\Broadcasting\PrivateChannel;
|
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
|
use Illuminate\Foundation\Events\Dispatchable;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class ReportDutyUpdated implements ShouldBroadcast
|
|
{
|
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
|
|
|
public function __construct(
|
|
public ReportDuty $reportDuty,
|
|
public string $action
|
|
) {}
|
|
|
|
public function broadcastOn(): array
|
|
{
|
|
return [new PrivateChannel('headquarters')];
|
|
}
|
|
|
|
public function broadcastAs(): string
|
|
{
|
|
return 'report-duty.updated';
|
|
}
|
|
|
|
public function broadcastWith(): array
|
|
{
|
|
return [
|
|
'id' => $this->reportDuty->id,
|
|
'department_id' => $this->reportDuty->rf_department_id,
|
|
'department' => $this->reportDuty->department?->name_short,
|
|
'action' => $this->action,
|
|
'period_start' => $this->reportDuty->period_start?->toISOString(),
|
|
'period_end' => $this->reportDuty->period_end?->toISOString(),
|
|
'sent_at' => now()->toISOString(),
|
|
];
|
|
}
|
|
}
|