KTV/app/Observers/RoomObserver.php
allen.yan ae5ed4aa1f Swagger 都改到ApiResponse 輸出
Swagger Room加入TcpSocketClient
Swagger room 加入 設備註冊,設備開關
Swagger room 有異動需要寫記錄
20250519
2025-05-19 16:08:35 +08:00

60 lines
1.2 KiB
PHP

<?php
namespace App\Observers;
use Illuminate\Support\Facades\Auth;
use App\Models\Room;
use App\Models\RoomStatusLog;
class RoomObserver
{
/**
* Handle the Room "created" event.
*/
public function created(Room $room): void
{
//
}
/**
* Handle the Room "updated" event.
*/
public function updated(Room $room): void
{
// 檢查是否有變更狀態
if ($room->wasChanged('status')) {
RoomStatusLog::create([
'room_id' => $room->id,
'user_id' => Auth::id(), // 若是 console 或系統自動操作可能為 null
'status' => $room->status,
'message' => 'started_at:'.$room->started_at.',ended_at:'.$room->ended_at,
]);
}
}
/**
* Handle the Room "deleted" event.
*/
public function deleted(Room $room): void
{
//
}
/**
* Handle the Room "restored" event.
*/
public function restored(Room $room): void
{
//
}
/**
* Handle the Room "force deleted" event.
*/
public function forceDeleted(Room $room): void
{
//
}
}