43 lines
1.0 KiB
PHP
43 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Events;
|
|
|
|
use Illuminate\Broadcasting\Channel;
|
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
|
use Illuminate\Foundation\Events\Dispatchable;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class AttendanceUpdated implements ShouldBroadcastNow
|
|
{
|
|
use Dispatchable, SerializesModels;
|
|
|
|
public function __construct(
|
|
public int $user_id,
|
|
public string $status,
|
|
public ?string $check_in = null,
|
|
public ?string $check_out = null
|
|
) {}
|
|
|
|
public function broadcastOn(): Channel
|
|
{
|
|
// Global channel untuk semua perubahan absensi
|
|
return new Channel('attendance.global');
|
|
}
|
|
|
|
// Supaya JS bisa listen('.attendance.updated')
|
|
public function broadcastAs(): string
|
|
{
|
|
return 'attendance.updated';
|
|
}
|
|
|
|
public function broadcastWith(): array
|
|
{
|
|
return [
|
|
'user_id' => $this->user_id,
|
|
'status' => $this->status,
|
|
'check_in' => $this->check_in,
|
|
'check_out' => $this->check_out,
|
|
];
|
|
}
|
|
}
|